Home > Back-end >  C binary tree based binary tree traversal again after why can not the output of the C
C binary tree based binary tree traversal again after why can not the output of the C

Time:11-24

#include

using namespace std;
The template & lt; Typename T>
The class Bintree;
The template & lt; Typename T>
The class Binode
{
Friend class Bintree;


Public:
T data;
Binode * lchild;
Binode * rchild;
Binode item (T) {data=https://bbs.csdn.net/topics/item; Lchild=NULL; Rchild=NULL; }
~ Binode () {}
};

The template & lt; Typename T>
The class Bitree
{
Private:
Int size;


Public:
Binode * root;
Bitree () {size=0; The root=NULL; Cout<& lt;" According to the antecedent sequence input: "& lt; ~ Bitree ();
Void CreatTree (Binode * & amp; Curnode);
Void Preorder (Binode * root);
Void Inorder (Binode * root);
Void Postorder (Binode * root);
Void Leverorder (Binode * root);
Binode * & amp; GetRoot () {return root; }


};
The template & lt; Typename T>
Bitree : : ~ Bitree ()
{
}
The template & lt; Typename T>
Void Bitree : : CreatTree (Binode * & amp; Curnode)
{
char ch;
Cin> Ch;
If (ch=='#') curnode=NULL;
The else {
Curnode=new Binode (ch);

Curnode - & gt; data=https://bbs.csdn.net/topics/ch;
CreatTree (curnode - & gt; Lchild);
CreatTree (curnode - & gt; Rchild);
}

}
The template & lt; Typename T>
Void Bitree : : Preorder (Binode * root)
{
CoutPreorder (root - & gt; Lchild);
Preorder (root - & gt; Rchild);
}
Int main ()

{
Bitree Mytree;
Cout<& lt;" Creating a successful "& lt; Cout<& lt;" Preorder traversing binary tree "& lt; Mytree. Preorder (mytree. Root);


}
Input and operation results:

How can not C output?

CodePudding user response:

Big help!!!!!!

CodePudding user response:

First order code wrong.
You don't have to judge whether the current node is NULL, it still recursion bottom go to, must be wrong

CodePudding user response:

Understand the understand the stupid
  • Related