#include
#include
Typedef char datatype.
Typedef struct node
{
Datatype data;
Struct node * lchild;
Struct node * rchild;
} bitnode, * bitree;
//create a binary list
Void createbitree (bt) bitree *
{
char ch;
Ch=getchar ();
If (ch=')
Bt=NULL;
The else
{
* bt=(bitree) malloc (sizeof (bitnode));
Bt (*) - & gt; data=https://bbs.csdn.net/topics/ch;
Createbitree (& amp; (bt) (* - & gt; Lchild));
Createbitree (& amp; (bt) (* - & gt; Rchild));
}
}
//first order traversing binary tree
Void preorder (bitree root)
{
If (root!=NULL)
{
Printf (" % c ", root - & gt; The data);//access to the root node
Preorder (root - & gt; Lchild);//sequence traversal first left subtree
Preorder (root - & gt; Rchild);//first sequence traversal right subtree
}
}
//sequence traversal of binary tree
Void inorder (bitree root)
{
If (root!=NULL)
{
Inorder (root - & gt; Lchild);//sequence traversal first left subtree
Printf (" % c ", root - & gt; The data);//access to the root node
Inorder (root - & gt; Rchild);//first sequence traversal right subtree
}
}
//order after traversing binary tree
Void postorder (bitree root)
{
If (root!=NULL)
{
Postorder (root - & gt; Lchild);//sequence traversal first left subtree
Postorder (root - & gt; Rchild);//first sequence traversal right subtree
Printf (" % c ", root - & gt; The data);//access to the root node
}
}
Void main ()
{
Bitree p;
Printf (" please enter the established binary tree \ n ");
Createbitree (& amp; P);
Printf (" first sequence traversal output binary tree \ n ");
Preorder (p);
Printf (" output sequence traversal of binary tree \ n ");
Inorder (p);
Printf (" after the sequence traversal output binary tree \ n ");
Postorder (p);
}
Where is wrong