I got some problem while printing the tree LEVEL wise
The following code doesn't print the nodes properly
please suggest something.....



void bst::level(bst *root)
{
   queue q1,q2;
   bst *p1,*p2;
   bst *r=root;
   if(r==NULL)
           return;
   q1.insert(r);
   cout<<"\n"<<r->data;
   while(!q1.empty())
   {
          cout<<"\n";
          q2.init();
          while(!q1.empty())
          {
                  p1=q1.del();
                  if(p1->left !=NULL)
                  {
                          q2.insert(p1->left);
                          cout<<"  "<<p1->left->data;
                  }
                  if(p1->right !=NULL)
                  {
                          q2.insert(p1->right);
                          cout<<"  "<<p1->right->data;
                  }
          }
          q1=q2;
    }
}

Reply via email to