xAbhishek.com

Breadth-First Binary Tree Traversal

This explanation is excellent.

So is this code:
void breadthFirst()
{
 Queue q;
 tree_node *p=root;
 if(p!=0)
 {
  q.push(p);
  while(!q.empty())
  {
  p= q.pop();
  cout<<p->info<<” “;
  if(p->left!=0)
  q.push(p->left);
  if(p->right!=0)
  q.right(p->right);
  }
 }
}

Ping "Breadth-First Binary Tree Traversal": http://xabhishek.com/2008/04/23/breadth-first-binary-tree-traversal/trackback/

No comments

Write comment








Copyright 2008 Abhishek Nandakumar I Google, Therefore I Am