That's a breadth first search. The only gotcha is that the usage of
push and pop maybe misleading (implying that we're using stack). But
actually it should use FIFO.  You should view each push as enqueue and
pop as dequeue. It will traverse the tree layer by layer, left to
right.

On 3/24/07, vim <[EMAIL PROTECTED]> wrote:
>
>
>
> On Mar 23, 8:17 am, "tuesday" <[EMAIL PROTECTED]> wrote:
> > u can use a queen in bfs traverse
> >
> > void visit(Node* r)
> > {
> >
> > }
> >
> > void BF_Traverse(Node* r)
> > {
> >    queen<Node*> q;
> >    q.push(r);
> >    while(!q.empty())
> >    {
> >           Node* t = *q.front();
> >           q.pop();
> >           visit(t);
> >           if(t->left !=0)
> >              q.push(t->left);
> >           if(t->right!=0)
> >              q.push(t->right);
> >    }
> >
> > }
>
>
>
>
>
> any one plz explain the above code.
>
>
> >
>


-- 
Fear of the LORD is the beginning of knowledge (Proverbs 1:7)

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---

Reply via email to