#include
#include
Typedef char ElemType;
Typedef struct BiTNode {
ElemType data;
Struct lchild BiTNode * and * rchild;
}
BiTNode, * BiTree;
The Status CreateBiTree (BiTree & amp; T) {
ElemType data;
The scanf (" % c ", & amp; The data);
If (=='^' data) T=NULL;
The else {
if(! (T=(BiTree) malloc (sizeof (BiTNode)))) exit (OVERFLOW);
T - & gt; data=https://bbs.csdn.net/topics/data;
CreateBiTree (T - & gt; Lchild);
CreateBiTree (T - & gt; Rchild);
}
Return ok; }
The Status PreOderTraverse (BiTree T, Status (* Visit) (ElemType e)) {
If (T)
{if (Visit (T - & gt; Data) if (PreOderTraverse (T - & gt; Lchild, Visit) if (PreOderTraverse (T - & gt; Rchild, Visit)
Return ok;
Return the error;
} the else return ok; }
The Status InOderTraverse (BiTree T, Status (* Visit) (ElemType e)) {
If (T) {
If (Visit (T - & gt; Data))
If (InOderTraverse (T - & gt; Lchild, Visit)
If (Visit (T - & gt; Data) if (InOderTraverse (T - & gt; Rchild, Visit)
Return ok;
Return the error;
} the else return ok;
}
The Status PostOderTraverse (BiTree T, Status (* Visit) (TElemType e)) {if (T) {if (PostOderTraverse (T - & gt; Lchild, Visit) if (PostOderTraverse (T - & gt; Rchild, Visit the if (Visit) (T - & gt; Data))
Return ok;
Return the error;
} the else return ok;
} int main ()
{void Test (BiTree & amp; T)
{CreateBiTree (& amp; T);
Printf (" PreOrderTraverse is: "); PreOrder (T, PrintElement);
Printf (" \ n ");
Printf (" InOrderTraverse is: ");
InOrder (T, PrintElement);
Printf (" \ n ");
Printf (" PostOrderTraverse is: "); PostOrder (T, PrintElement));
Printf (" \ n ");
} return ok;
}
CodePudding user response:
So what is the problem?CodePudding user response:
I think: the second sequence traversal is supposed to be like this:The Status InOderTraverse (BiTree T, Status (* Visit) (ElemType e)) {
If (T) {
If (InOderTraverse (T - & gt; Lchild, Visit)
If (Visit (T - & gt; Data))
If (Visit (T - & gt; Data) if (InOderTraverse (T - & gt; Rchild, Visit)
Return ok;
Return the error;
} the else return ok;
}
CodePudding user response: