Synchronously traverses the tree breadth first.
328413
function traverseBreadthFirstSync(rootNode, options) {
  options = extend({
    subnodesAccessor: function(node) { return node.subnodes; },
    userdataAccessor: function(node, userdata) { return userdata; },
    onNode: function(node, userdata) {},
    userdata: null
  }, options);

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

  while (queue.length>0) {
    var front = queue.shift();
    var node = front[0];
    var data = front[1];

    options.onNode(node, data);

    var subnodeData = options.userdataAccessor(node, data);
    var subnodes = options.subnodesAccessor(node);
    for (var i=0; i<subnodes.length; i++) {
      queue.push([subnodes[i], subnodeData]);
    }
  }
  return rootNode;
}
355768
private void postTraversalProcessing() {
		int nc1 = treeSize;
		info[KR] = new int[leafCount];
		info[RKR] = new int[leafCount];

		int lc = leafCount;
		int i = 0;

		// compute left-most leaf descendants
		// go along the left-most path, remember each node and assign to it the path's
		// leaf
		// compute right-most leaf descendants (in reversed postorder)
		for (i = 0; i < treeSize; i++) {
			if (paths[LEFT][i] == -1) {
				info[POST2_LLD][i] = i;
			} else {
				info[POST2_LLD][i] = info[POST2_LLD][paths[LEFT][i]];
			}
			if (paths[RIGHT][i] == -1) {
				info[RPOST2_RLD][treeSize - 1 - info[POST2_PRE][i]] =
						(treeSize - 1 - info[POST2_PRE][i]);
			} else {
				info[RPOST2_RLD][treeSize - 1 - info[POST2_PRE][i]] =
						info[RPOST2_RLD][treeSize - 1
								- info[POST2_PRE][paths[RIGHT][i]]];
			}
		}

		// compute key root nodes
		// compute reversed key root nodes (in revrsed postorder)
		boolean[] visited = new boolean[nc1];
		boolean[] visitedR = new boolean[nc1];
		Arrays.fill(visited, false);
		int k = lc - 1;
		int kR = lc - 1;
		for (i = nc1 - 1; i >= 0; i--) {
			if (!visited[info[POST2_LLD][i]]) {
				info[KR][k] = i;
				visited[info[POST2_LLD][i]] = true;
				k--;
			}
			if (!visitedR[info[RPOST2_RLD][i]]) {
				info[RKR][kR] = i;
				visitedR[info[RPOST2_RLD][i]] = true;
				kR--;
			}
		}

		// compute minimal key roots for every subtree
		// compute minimal reversed key roots for every subtree (in reversed postorder)
		int parent = -1;
		int parentR = -1;
		for (i = 0; i < leafCount; i++) {
			parent = info[KR][i];
			while (parent > -1 && info[POST2_MIN_KR][parent] == -1) {
				info[POST2_MIN_KR][parent] = i;
				parent = info[POST2_PARENT][parent];
			}
			parentR = info[RKR][i];
			while (parentR > -1 && info[RPOST2_MIN_RKR][parentR] == -1) {
				info[RPOST2_MIN_RKR][parentR] = i;
				parentR =
						info[POST2_PARENT][info[RPOST2_POST][parentR]]; // get parent's postorder
				if (parentR > -1) {
					parentR = treeSize - 1 - info[POST2_PRE][parentR]; // if parent exists get its
					// rev. postorder
				}
			}
		}
	}
740530
def _bfs(node, visited):
    """"""
    queue = collections.deque()
    queue.appendleft(node)
    while queue:
        node = queue.pop()
        if node not in visited:
            if node.lo is not None:
                queue.appendleft(node.lo)
            if node.hi is not None:
                queue.appendleft(node.hi)
            visited.add(node)
            yield node
829352
function (callback, context) {
        callback.call(context, this);
        var _children = this._children;
        for(var i = 0, len = _children.length; i < len; i++) {
            _children[i].traverse(callback, context);
        }
    }
1112786
def bfs(graph, start):
    
    # maintain a queue of paths
    queue = []
    visited = []
    # maintain a queue of nodes
    # push the first path into the queue
    queue.append([['', start]])
    while queue:
        # get the first path from the queue
        path = queue.pop(0)
        # get the last node from the path
        node = path[-1][1]
        if node.stateid not in visited:
            visited.append(node.stateid)
            # path found
            if node.final != TropicalWeight(float('inf')):
                return "".join([mnode[0] for mnode in path])
            # enumerate all adjacent nodes, construct a new path and push
            # it into the queue
            for arc in node.arcs:
                char = graph.isyms.find(arc.ilabel)
                next_state = graph[arc.nextstate]
                # print next_state.stateid
                if next_state.stateid not in visited:
                    new_path = list(path)
                    new_path.append([char, next_state])
                    queue.append(new_path)
933100
private static Tree traverse(Tree parent, List<Tree> kids, Tree node) {
        for (Tree kid : kids) {
            if (kid == node) {
                return parent;
            }

            Tree ret = node.parent(kid);
            if (ret != null) {
                return ret;
            }
        }
        return null;
    }
53235
@Override
  public void apply(TreeVisitor tp) {
    for (int i = 0, size = parseTrees.size(); i < size; i++) {
      tp.visitTree(parseTrees.get(i));
    }
    // or could do as Iterator but slower
    // Iterator iter = parseTrees.iterator();
    // while (iter.hasNext()) {
    //    tp.visitTree((Tree) iter.next());
    // }
  }
767381
function traverseRevTree(revs, callback) {
  var toVisit = revs.slice();

  var node;
  while ((node = toVisit.pop())) {
    var pos = node.pos;
    var tree = node.ids;
    var branches = tree[2];
    var newCtx =
      callback(branches.length === 0, pos, tree[0], node.ctx, tree[1]);
    for (var i = 0, len = branches.length; i < len; i++) {
      toVisit.push({pos: pos + 1, ids: branches[i], ctx: newCtx});
    }
  }
}
1200706
private void completeNode() {
        if (nodeBuilder == null) {
            return;
        }
        nodeBuilder.setOperation(getOperationName());
        nodeBuilder.setTimestamp(TimeUtil.toMicros(getStart()));
        nodeBuilder.setDuration(TimeUnit.NANOSECONDS.toMicros(getDuration().toNanos()));

        // Process the span to initialise the node
        traceContext.getNodeProcessors().forEach(np -> np.process(traceContext, this, nodeBuilder));

        traceContext.endProcessingNode();
        nodeBuilder = null;
    }
388939
public boolean goForward() {
	if (currentNode.hasChildren()) {
	    currentNode = currentNode.getChildren().get(0);
	    return true;
	} else if (currentNode.getParent() == null) {
	    return false;
	}
	while (true) {
	    N parent = currentNode.getParent();
	    if ((parent == null) || (currentNode == tree)) {
		return false;
	    }
	    int index = parent.getChildren().indexOf(currentNode);
	    if (parent.getChildren().size() > index + 1) {
		currentNode = parent.getChildren().get(index + 1);
		return true;
	    } else {
		currentNode = parent;
	    }
	}
    }
377297
def walk(self, node):
        ""
        node = self.visit(node)

        if node is None:
            return None

        if isinstance(node, parso.tree.BaseNode):
            walked = map(self.walk, node.children)
            node.children = [child for child in walked if child is not None]

        return node
939725
public void synchronize(DefaultTreeModel treeModel, Tree<E> tree) throws IOException, SQLException {
		assert SwingUtilities.isEventDispatchThread() : ApplicationResources.accessor.getMessage("assert.notRunningInSwingEventThread");
		synchronize(treeModel, tree.getRootNodes());
	}
479396
function traverse(object, visitor) {
  let child;
  if (!object) return;

  let r = visitor.call(null, object);
  if (r === STOP) return STOP; // stop whole traverse immediately
  if (r === SKIP_BRANCH) return; // skip going into AST branch

  for (let i = 0, keys = Object.keys(object); i < keys.length; i++) {
    let key = keys[i];
    if (IGNORED_KEYS.indexOf(key) !== -1) continue;

    child = object[key];
    if (typeof child === 'object' && child !== null) {
      if (traverse(child, visitor) === STOP) {
        return STOP;
      }
    }
  }
}
682159
public Iterator breadthFirst() {
        return new Iterator() {
            private final List list = new LinkedList();
            private Iterator iter = iterator();
            private GPathResult next = getNextByBreadth();

            public boolean hasNext() {
                return this.next != null;
            }

            public Object next() {
                try {
                    return this.next;
                } finally {
                    this.next = getNextByBreadth();
                }
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }

            private GPathResult getNextByBreadth() {
                List children = new ArrayList();
                while (this.iter.hasNext() || !children.isEmpty()) {
                    if (this.iter.hasNext()) {
                        final GPathResult node = (GPathResult) this.iter.next();
                        this.list.add(node);
                        this.list.add(this.iter);
                        children.add(node.children());
                    } else {
                        List nextLevel = new ArrayList();
                        for (Object child : children) {
                            GPathResult next = (GPathResult) child;
                            Iterator iterator = next.iterator();
                            while (iterator.hasNext()) {
                                nextLevel.add(iterator.next());
                            }
                        }
                        this.iter = nextLevel.iterator();
                        children = new ArrayList();
                    }
                }
                if (this.list.isEmpty()) {
                    return null;
                } else {
                    GPathResult result = (GPathResult) this.list.get(0);
                    this.list.remove(0);
                    this.iter = (Iterator) this.list.get(0);
                    this.list.remove(0);
                    return result;
                }
            }
        };
    }
988108
def walk(node):
    
    from collections import deque
    todo = deque([node])
    while todo:
        node = todo.popleft()
        todo.extend(iter_child_nodes(node))
        yield node
945611
public static final <T> Stream<T> breadthFirst(T root, Function<? super T, ? extends Stream<T>> edges)
    {
        return BreadthFirst.stream(root, edges);
    }
391127
function traverse(object, iterator, parent, parentProperty) {
        var key, child;
        if (iterator(object, parent, parentProperty) === false)
          return;
        for (key in object) {
          if (!object.hasOwnProperty(key))
            continue;
          if (key == 'location' || key == 'type')
            continue;
          child = object[key];
          if (typeof child == 'object' && child !== null)
            traverse(child, iterator, object, key);
        }
      }