Home > Back-end >  In c compiled binary tree print is always wrong, but it can compile
In c compiled binary tree print is always wrong, but it can compile

Time:09-26

BITREE is the name of the class, btree is struct
Queue is my definition of queue is used to help achieve print, queue function after the test is correct

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
The queue q;

Struct btree
{
Elementtype data;
Lchild btree * and * rchild;
};

//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Void BITREE: : print_tree (btree * root) const//this place parameter types went wrong?
{
If (root==NULL) return;
If (root - & gt; Lchild==NULL& & Root - & gt; Rchild==NULL)
{
Q.a ppend (root - & gt; The data);
Q.o utput ();
Q.r ear_pop ();
return;
}
The else
{
Q.a ppend (root - & gt; The data);
Print_tree (root - & gt; Lchild);
Print_tree (root - & gt; Rchild);
Q.r ear_pop ();
return;
}
}

Still hope directly
  • Related