输入:abd??e?g??cf???
#include "iostream"
using namespace std;
struct Node
{
char data;
Node*Lchild;
Node*Rchild;
};
class tree
{
public:
tree();
Node*Createtree(Node*T);
void InorderTraverse(Node*T);
void bianli(int i);
private:
Node*head;
};
tree::tree()
{
head=Createtree(head);
cout<<head->data<<" "
<<(head->Lchild)->data;//调试到这里根节点的左右子树没有相应的值
}
Node*tree::Createtree(Node*T)
{
char ch;
cin>>ch;
if(ch=='?')
{
T=NULL;
}
else
{
T=new Node;
T->data=ch;
Createtree(T->Lchild);
Createtree(T->Rchild);
return T;
}
}
void tree::InorderTraverse(Node*T)
{
if(T!=NULL)
{
InorderTraverse(T->Lchild);
cout<<T->data<<" ";
InorderTraverse(T->Rchild);
}
}
void tree::bianli(int i)
{
if(i==1)InorderTraverse(head);
}
int main()
{
tree a;
a.bianli(1);
}
萧十郎
富国沪深