One of the easiest ways to do this is to reverse input and then use the "root right left" sequence to build two-prong trees.
*********************************/
/**//**********gamesduan*********/
/**//**********bitreeinlast*********/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#define NULL 0
int n=0;
typedef struct BITNODE ... {//Tree structure
char data;
struct Bitnode *lchild,*rchild;
}bitnode;
Bitnode *createbitreeinpre ()//First Order recursive achievements
{
Bitnode *m;
Char ch;
scanf ("%c", &ch);
if (ch== ') m=null;
Else
{
if (!) ( m= (Bitnode *) malloc (sizeof (Bitnode)))
Exit (0);
m->data=ch;
M->lchild=createbitreeinpre ();
M->rchild=createbitreeinpre ();
}
return m;
}
Bitnode *createbitreeinlast1 ()///The first method, input in the form of reverse input, input as "C Empty B empty"
{
Bitnode *t;
Char ch;
scanf ("%c", &ch);
if (ch== ')
T=null;
Else
{
t= (Bitnode *) malloc (sizeof (Bitnode));
t->data=ch;
T->rchild=createbitreeinlast2 (); Create right subtree First
T->lchild=createbitreeinlast2 (); Then create Zuozi
}
return T;
}
void preorder (Bitnode *t)//first-order recursive output
{
if (t!=null)
{
printf ("%c", t->data);
Preorder (T->lchild);
Preorder (T->rchild);
}
}
void Main ()
{
Bitnode *t=new Bitnode;
T=createbitreeinpre (); First Order
T=createbitreeinlast1 (); After 1
Preorder (t);
}