Home > other >  Binary tree non-recursive calendar calculation method
Binary tree non-recursive calendar calculation method

Time:09-18

To teach the book in a binary tree non-recursive sequence through calendar calculation method, feeling to write wrong, the last four lines into a dead xunhua, strives for the great god teach
-- -- -- -- -- -- -- -- -- -- -- --
//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/104514746

CodePudding 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);
}
  • Related