// Walk performs a BFS (breadth-first search) on the tree structure of nodes
// and executes the argument function on each node.
// If the return value is false, the search ends.
Walk performs a BFS (breadth-first search) on the tree structure of nodes
and executes the argument function on each node.
If the return value is false, the search ends.
// Walk performs a BFS ( breadth - first search ) on the tree structure of nodes // and executes the argument function on each node . // If the return value is false the search ends .
func Walk(node *Node, fn func(*Node) bool) {
	queue := make([]*Node, 0)
	queue = append(queue, node)
	for len(queue) != 0 {
		var pn *Node
		pn, queue = queue[0], queue[1:]
		for _, cn := range pn.Children {
			queue = append(queue, cn)
		}
		if !fn(pn) {
			return
		}
	}
}
func Walk ( node * Node , fn func ( * Node ) bool ) { queue := make ( [ ] * Node , 0 ) queue = append ( queue , node ) for len ( queue ) != 0 { var pn * Node pn , queue = queue [ 0 ] , queue [ 1 : ] for _ , cn := range pn . Children { queue = append ( queue , cn ) } if ! fn ( pn ) { return } } }
Walk performs a BFS (breadth-first search) on the tree structure of nodes
and executes the argument function on each node.
Walk performs a BFS ( breadth - first search ) on the tree structure of nodes and executes the argument function on each node .
// initialize search queue for BFS. // start BFS // get the first node from queue // add children nodes to the search queue // execute function