# include "btree. H"
Int main ()
{
Char STR [20].
//A
CreateBTree (tree, "A, (B (G), (D), C (E, F))");//error here
DispBTree tree (*);
//B
BTHeight tree (*);
//C
BTNode * p;
Printf (" please input node: ");
The scanf (" % c ", p);
LchildNode (p);
//D
DestroyBTree (tree);
DispBTree tree (*);
}
//the header file
#include
#include
#include
Typedef struct node {
char data;
Struct node * lchild;
Struct node * rchild;
} BTNode;
Void CreateBTree (BTNode * * b, char * STR) {
BTNode * St [20], * p;
Int top=1, k, j=0;
char ch;
Ch=STR [j];//here suggests the Program received signal SIGSEGV, Segmentation fault
while(ch!='\ 0')
{
The switch (ch)
{
Case '(' : top++; St [top]=p; k=1; break;
Case ') : top -; break;
Case ', ': k=2; break;
Default: p=(BTNode *) malloc (sizeof (BTNode));
P - & gt; Data=https://bbs.csdn.net/topics/ch;
P - & gt; Lchild=p - & gt; Rchild=NULL;
If ((* b)==NULL)
* b=p;
The else
{
The switch (k)
{
Case 1: St [top] - & gt; Lchild=p; break;
Case 2: St [top] - & gt; Rchild=p; break;
}
}
}
j++;
Ch=STR [j];
Printf (" % c ", ch);
}
}