/* (1) Build a two-fork tree with n nodes and store it with a binary list
Construct the structure type of node;
The sequence of the two-fork tree is given according to the first order traversal method.
Dynamic request memory space storage new node;
Establish the relationship between nodes;
(2) Pre-order (or middle order, post) traverse the two-fork tree * *
#include <stdio.h>
#include <malloc.h>
Char DataType;
typedef struct NODE
{
char data;
struct Node *lchild;
struct Node *rchild;
}bitnode,*bitree;
Bitree creat ()
{
Bitnode *root;
char data;
Char ch;
printf ("Please enter:");
scanf ("%c", &ch);
GetChar ();
if (ch== '! ')
Root=null;
Else
{
root= (Bitnode *) malloc (sizeof (Bitnode));
root->data=ch;
Root->lchild=creat ();
Root->rchild=creat ();
}
return root;
}
void preorder (Bitree root)
{
if (root!=null)
{
printf ("%c", root->data);
Preorder (Root->lchild);
Preorder (Root->rchild);
}
}
void Inorder (Bitree root)
{
if (root!=null)
{
Inorder (Root->lchild);
printf ("%c", root->data);
Inorder (Root->rchild);
}
}
void Postorder (Bitree root)
{
if (root!=null)
{
Postorder (Root->lchild);
Postorder (Root->rchild);
printf ("%c", root->data);
}
}
void Main ()
{
Bitnode *root=null;
Root=creat ();
printf ("The tree's pre-order traversal in sequence: \ n");
Preorder (root);
printf ("\ n");
Inorder (root);
printf ("\ n");
Postorder (root);
printf ("\ n");
}
:
Pre-order, middle order, sequential traversal of binary tree