Home > Back-end >  Under a tree ace to help me see me this clue binary tree recursive problem
Under a tree ace to help me see me this clue binary tree recursive problem

Time:09-25

#include
#include

# define Max 10

Typedef int ElemType;

Typedef struct BiTNode//tree structure
{
ElemType data;
Struct lchild BiTNode * and * rchild;
Int ltag rtag;
} BiTNode, * BiTree;

BiTree pre=NULL;

Void BaseData (char * * s)//create the array
{
Char * q;
int i;
Printf (" please input you want to input the data length, if the length of the overrun intercept length corresponding part of the character. \ n ");
The scanf (" % d ", & amp; I);
Q=(char *) malloc (sizeof (char) * I);
Printf (" please enter the characters you: \ n ");
The scanf (" % s ", q);
* s=q;
Q [I]='\ 0';
}

Void CreateTree BiTree * t, char * (s)//using the array spanning tree
{
BiTree stack (Max), p=NULL;
Int top=1, k, j=0;
Char ch;
* t=NULL;
Ch=s [j];
While (ch!='\ 0')
{
The switch (ch)
{
Case '('
Stack [+ + top]=p;
k=1;
break;
Case ') :
Top -;
break;
Case ', ':'
k=2;
break;
Default:
P=(BiTree) malloc (sizeof (BiTNode));
p-> data=https://bbs.csdn.net/topics/ch;
p-> Lchild=p - & gt; Rchild=NULL;
p-> Ltag=p - & gt; Rtag=0;
If (* t==NULL)
* t=p;
The else
{
The switch (k)
{
Case 1:
Stack [top] - & gt; Lchild=p;
break;
Case 2:
Stack [top] - & gt; Rchild=p;
break;
}
}
}
Ch=s [+ + j];
}
}

Void vist (BiTree p)
{
If (p!=NULL)
{
Printf (" the current node are: \ n ");
Printf (" % c ", p - & gt; The data);
printf("\n");
}
}

Void ZXBL BiTree (p)//sequence traversal of binary tree
{
If (p==NULL)
return;
ZXBL (p - & gt; Lchild);
Vist (p);
ZXBL (p - & gt; Rchild);
}

Void ZXXSBL (BiTree * p)//in order clues HuaEr quadtree process: 1
{
Printf (" * * * * * * * * * * \ n ");//A (B (G), (D), C (E, F))
//printf (" % c \ n ", (* p) - & gt; The data);//test code
If ((* p)!=NULL)
{
ZXXSBL (& amp; ((* p) - & gt; Lchild));
Printf (" @ @ @ @ @ @ @ @ @ @ @ @ @ @ \ n ");
If ((* p) - & gt; Lchild==NULL)
{
(* p) - & gt; Lchild=(pre);
(* p) - & gt; Ltag=1;
}
If ((pre) - & gt; Rchild==NULL& & (pre)!=NULL)
{
(pre) - & gt; Rchild=(* p);
(pre) - & gt; Rtag=1;
}
(pre)=(* p);
ZXXSBL (& amp; (* p) - & gt; Rchild);
}
}

Void main ()
{
Char * s;
BiTree tree;
BaseData (& amp; S);
CreateTree (& amp; Tree, s);
ZXXSBL (& amp; A tree);//clues HuaEr quadtree
Printf (" clues to complete. \ n ");
//XXBL (tree);

}

//A (B (G), (D), C (E, F))

/*
This is the clue of the binary tree recursive, but like a recursive failed,,, why
Test data
Length: 18
Character array: A (B (G), (D), C (E, F))
*/

CodePudding user response:

 for help for help
  • Related