or this:

Here is an implementation of breadth--first search. Notice that a queue is used instead of a stack; otherwise, this routine is virtually identical to the second implementation of depth--first search:

tree_type

bfs_queue(tree_type tree, BOOL (*predicate)(tree_type))

{

queue_type queue = create_queue();

tree_type guess;

enqueue(tree, queue);

while (empty_(queue) == FALSE)

{

guess = dequeue(queue);

if (empty_tree(guess) == TRUE)

continue;

if (predicate(guess) == TRUE)

return guess;

enqueue(left_child(guess),

enqueue(right_child(guess)

}

return the_empty_tree;

}