Depth-first search and postorder of a tree rooted at node j.
326530
def __tdfs(j, k, head, next, post, stack):
    
    top = 0
    stack[0] = j
    while (top >= 0):
        p = stack[top]
        i = head[p]
        if i == -1:
            top -= 1
            post[k] = p
            k += 1
        else:
            head[p] = next[i]
            top += 1
            stack[top] = i

    return k
955028
public static List<ITree> postOrder(ITree tree) {
        List<ITree> trees = new ArrayList<>();
        postOrder(tree, trees);
        return trees;
    }
1368922
protected void searchNode(P target, KdTree.Node n) {
		while( n != null) {
			checkBestDistance(n, target);

			if( n.isLeaf() )
				break;

			// select the most promising branch to investigate first
			KdTree.Node nearer,further;

			double splitValue = distance.valueAt( (P)n.point , n.split );

			if( distance.valueAt( target , n.split ) <= splitValue ) {
				nearer = n.left;
				further = n.right;
			} else {
				nearer = n.right;
				further = n.left;
			}

			// See if it is possible for 'further' to contain a better node
			double dx = splitValue - distance.valueAt(target, n.split );
			if( further != null && canImprove(dx*dx) ) {
				addToQueue(dx*dx, further, target );
			}

			n = nearer;
		}
	}
1295349
def deepest_node((subj, pred, obj), graph):
    """"""
    # i don't fully accept the premise that this docstring presents
    # i'm not a docstring literalist
    to_return = []

    def _deepest_node((subj, pred, obj), graph):
        children = []
        if isinstance(obj, rt.BNode):
            for s, p, o in graph:
                if str(s) == str(obj):
                    children.append((s, p, o))
            for s, p, o in children:
                s1, p1, o1 = _deepest_node((s, p, o), graph)
                # coupling *smacks hand with ruler*
                if "rNews" in str(o1) and (s1, p1, o1) not in to_return:
                    to_return.append((s1, p1, o1))
            return (s1, p1, o1)
        else:
            return (subj, pred, obj)
    _deepest_node((subj, pred, obj), graph)

    return to_return
300524
function traverseBreadthFirst(rootNode, options) {
  options = extend({
    subnodesAccessor: function(node) { return node.subnodes; },
    userdataAccessor: function(node, userdata) { return userdata; },
    onNode: function(node, callback, userdata) { callback(); },
    onComplete: function(rootNode) {},
    userdata: null
  }, options);

  var queue = [];
  queue.push([rootNode, options.userdata]);

  (function next() {
    if (queue.length == 0) {
      options.onComplete(rootNode);
      return;
    }

    var front = queue.shift();
    var node = front[0];
    var data = front[1];

    options.onNode(node, function() {
      var subnodeData = options.userdataAccessor(node, data);
      var subnodes = options.subnodesAccessor(node);
      async.eachSeries(subnodes,
        function(subnode, nextNode) {
          queue.push([subnode, subnodeData]);
          async.setImmediate(nextNode);
        },
        function() {
          async.setImmediate(next);
        }
      );
    },
    data);
  })();
}
1298348
def _search_tree(self, name):
        """"""
        tpl1 = "{sep}{name}{sep}".format(sep=self._node_separator, name=name)
        tpl2 = "{sep}{name}".format(sep=self._node_separator, name=name)
        tpl3 = "{name}{sep}".format(sep=self._node_separator, name=name)
        return sorted(
            [
                node
                for node in self._db
                if (tpl1 in node)
                or node.endswith(tpl2)
                or node.startswith(tpl3)
                or (name == node)
            ]
        )
1144813
def _dfs_postorder(node, visited):
    """"""
    if node.lo is not None:
        yield from _dfs_postorder(node.lo, visited)
    if node.hi is not None:
        yield from _dfs_postorder(node.hi, visited)
    if node not in visited:
        visited.add(node)
        yield node
418615
private static boolean traverseTree(PointerTargetTree syn, PointerTargetNodeList ptnl, Synset source) {
        java.util.List MGListsList = syn.toList();
        for (Object aMGListsList : MGListsList) {
            PointerTargetNodeList MGList = (PointerTargetNodeList) aMGListsList;
            for (Object aMGList : MGList) {
                Synset toAdd = ((PointerTargetNode) aMGList).getSynset();
                if (toAdd.equals(source)) {
                    return true;
                }
            }
        }
        for (Object aPtnl : ptnl) {
            Synset toAdd = ((PointerTargetNode) aPtnl).getSynset();
            if (toAdd.equals(source)) {
                return true;
            }
        }
        return false;
    }
821268
function DOMPostOrder(root, visitFunc) {
	let node = root;
	while (true) {
		// Find leftmost (grand)child, and visit that first.
		while (node.firstChild) {
			node = node.firstChild;
		}
		visitFunc(node);
		while (true) {
			if (node === root) {
				return; // Visiting the root is the last thing we do.
			}
			/* Look for right sibling to continue traversal. */
			if (node.nextSibling) {
				node = node.nextSibling;
				/* Loop back and visit its leftmost (grand)child first. */
				break;
			}
			/* Visit parent only after we've run out of right siblings. */
			node = node.parentNode;
			visitFunc(node);
		}
	}
}
1368828
public Tree<K, V> lookup(Tree<K, V> tree, K x) {
        if (tree == null)
            return null;

        int cmp = ordering.compare(x, tree.getKey(kf));

        if (cmp < 0) return lookup(tree.getLeft(), x);
        else if (cmp > 0) return lookup(tree.getRight(), x);
        else return tree;
    }
905629
private LinkedList<T> computeRecursiveTraversal(T node, NodePath<T> nodePath) {
    try {


      LinkedList<T> imports = new LinkedList<>();
      Set<T> alreadyIncludedImports = new HashSet<>();

      for (T neighbor : this.traversalFunction.apply(node)) {
        nodePath.appendNode(neighbor);
        addSubtraversal(neighbor, imports, alreadyIncludedImports, nodePath);
        nodePath.popTail();
      }

      return imports;
    } catch (ExecutionException ee) {
      throw new RuntimeException(ee);
    }
  }
1007683
private static Treenode search(Iterable<Treenode> root, String text, ITreenodeSearch search) {
        for (Treenode node : root) {
            if (search.isMatch(node, text)) {
                return node;
            }
        }
        return null;
    }
784752
function depth(root) {
	let i = 0;
	let walker = document.createTreeWalker(root, 0xFFFFFFFF, {
		acceptNode: function(node){
			let nt = node.nodeType;
			return nt === 1 || nt === 3;
		}
	});

	while(walker.nextNode()) {
		i++;
	}
	return i;
}
673615
function findFirstTextNode(node) {
          var walker;

          if (node) {
            walker = new TreeWalker(node, node);

            for (node = walker.current(); node; node = walker.next()) {
              if (node.nodeType === 3) {
                return node;
              }
            }
          }
        }
777092
function tree(d, i) {
    var nodes = hierarchy.call(this, d, i),
        t = nodes[0],
        wt = wrapTree(t);

    wroot = wt;
    zerothWalk(wt, 0);
    firstWalk(wt);
    secondWalk(wt, 0);
    renormalize(wt);

    return nodes;
  }
429893
function depthFirst(node, parent) {
  var results = [];
  if (node && (typeof node === 'object')) {

    // valid node so push it to the list and set new parent
    //  don't overwrite parent if one was not given
    if ('type' in node) {
      if (parent !== undefined) {
        node.parent = parent;
      }
      parent = node;
      results.push(node);
    }

    // recurse object members using nested function call
    for (var key in node) {
      if (WHITE_LIST.test(key)) {
        var value = node[key];
        if (value && (typeof value === 'object')) {
          results.push.apply(results, depthFirst(value, parent));
        }
      }
    }
  }
  return results;
}
795447
private void preorderTreeDepth(INode root, HashMap<INode, Integer> order, HashMap<INode, Integer> depth) {
        order.clear();
        depth.clear();

        int num = 1;

        Deque<INode> stack = new ArrayDeque<INode>();
        stack.push(root);
        while (!stack.isEmpty()) {
            INode v = stack.pop();

            order.put(v, num++);
            if (!v.hasParent()) {
                depth.put(v, 0);
            } else {
                depth.put(v, depth.get(v.getParent()) + 1);
            }

            for (int i = v.getChildCount() - 1; i >= 0; i--) {
                stack.push(v.getChildAt(i));
            }
        }
    }