-- -- -- -- -- -- -- -- -- -- -- --
//use the stack of recursion sequence through calendar calculation method of traversing binary tree
Void Inorder1 BinTree (bt)
{//also USES binary linked list storage structure, and node values are assumed to be the character
SeqStack S; BinTNode * p;
InitStack (& amp; S); Push (& amp; S, bt);
while(! StackEmpty (& amp; S)) {
While (GetTop (& amp; S))
Push (& amp; S, GetTop (& amp; S) - & gt; Lchild);//until the left subtree is empty
P=Pop (& amp; S);
if(! StackEmpty (& amp; S)) {
Printf (" % c ", GetTop (& amp; S) - & gt; The data);//access to the root node
P=Pop (& amp; S); Push (& amp; S, p - & gt; Rchild);//right subtree into stack
}
}
}
CodePudding user response:
https://blog.csdn.net/weixin_43982698/article/details/104514746CodePudding user response:
Void LDR (BiTree T) {
BiTree t=t;
Stack S=createStackNode ();
Printf (" sequence traversal in: ");
While (t! The (S)===NULL | | isStackEmpty FALSE) {
If (t!=NULL) {
Push (S, t);
T=t - & gt; Lchild;
} else {
T=pop (S);
Printf (" % c ", t - & gt; The data);
T=t - & gt; Rchild;
}
}
printf("\n");
ClearStack (S);
}