Home > Back-end >  Excuse me each bosses, a program about the tree, the two mistakes, how to change
Excuse me each bosses, a program about the tree, the two mistakes, how to change

Time:09-24

# include
# include
Typedef struct BiTNode
{
Char data;
Struct lchild BiTNode * and * rchild;
} BiTNode, * BiTree;
Typedef struct
{
Char * base;
Char * top;
Int stacksize;
} SqStack;
Void CreateBiTree (BiTree & amp; T)
{
Char ch;
The scanf (" % c ", & amp; Ch);
If (ch=='#')
T=NULL;
The else
{
T=new BiTNode;
T - & gt; data=https://bbs.csdn.net/topics/ch;
CreateBiTree (T - & gt; Lchild);
CreateBiTree (T - & gt; Rchild);
}
}
Void beforeOrderTraverse (BiTree T)
{
If (T)
{
Printf (" % c ", T - & gt; The data);
BeforeOrderTraverse (T - & gt; Lchild);
BeforeOrderTraverse (T - & gt; Rchild);
}
}
Void InOrderTraverse (BiTree T)
{
If (T)
{
InOrderTraverse (T - & gt; Lchild);
Printf (" % c ", T - & gt; The data);
InOrderTraverse (T - & gt; Rchild);
}
}
Void afterOrderTraverse (BiTree T)
{
If (T)
{
AfterOrderTraverse (T - & gt; Lchild);
AfterOrderTraverse (T - & gt; Rchild);
Printf (" % c ", T - & gt; The data);
}
}
Int InitStack (SqStack & amp; S)
{
S.b ase=new char [100].
if(! S.b ase)
exit(0);
S.t op=S.b ase;
S.s tacksize=100;
return 1;
}
Int StackEmpty (SqStack S)
{
If (S.s tacksize==0)
return 1;
The else
return 0;
}
Int a Push (SqStack & amp; S, char e)
{
If (S.t op - S.b ase==S.s tacksize)
return 0;
* S.t op++=e;
return 1;
}
Int Pop (SqStack & amp; S, char & amp; E)
{
If (S.t op=S.b ase)
return 0;
E=* - S.t op;
return 1;
}
Void OrderTraverse (BiTree T)
{
InitStack (S);
BiTree p, q;
P=T;
Q=new BiTNode;
While (p | |! StackEmpty (S))
{
If (p)
{
Push (S, p);
P=p - & gt; Lchild;
}
The else
{
Pop (S, q);
Printf (" % c ", q - & gt; The data);
P=q - & gt; Rchild;
}
}
}
Int the Depth (BiTree T)
{
Int m, n;
If (T=NULL)
return 0;
The else
{
M=the Depth (T - & gt; Lchild);
N=the Depth (T - & gt; Rchild);
If (m> N)
Return (m + 1);
The else
Return (n + 1);
}
}
Int NodeCount (BiTree T)
{
If (T=NULL)
return 0;
The else
Return NodeCount (T - & gt; Lchild) + NodeCount (T - & gt; Rchild) + 1;
}
Int main ()
{
int a,b;
Printf (" preorder traversal generated binary tree: ");
CreateBiTree (T);
Printf (" preorder traversal of the above generated binary tree: ");
BedoreOrderTraverse (T);
Printf (" generated sequence traversal of the binary tree: ");
InOrderTraverse (T);
Printf (" sequence traversal generated binary tree after: ");
AfterOrderTraverse (T);
Printf (" non recursive way of traversing binary tree: ");
OrderTraverse (T);
A=the Depth (T);
Printf (" the depth of the output binary tree: % d \ n ", a);
B=NodeCount (T);
Printf (" output node number: % d \ n ", b);
return 0;
}
Error
C: \ Users \ \ Documents \ Cpp1 12597 CPP (91) : error C2065: 'S' : undeclared identifier
C: \ Users \ \ Documents \ Cpp1 12597 CPP (95) : fatal error C1903: unable to recover from previous error (s); Stopping compilation
Error executing cl. Exe.

CodePudding user response:

You stack S is not defined, that is, before you use the need to define it,

CodePudding user response:

You haven't defined tree T, in the C language definition before using,

CodePudding user response:

Your bottom of stack pointer and stack pointer storage is a binary tree node types of pointer instead of char BiTree type
  • Related