二叉树中序遍历的非递归算法
2019-11-28 本文已影响0人
shayito
Status InOrder(BT T){
InitStack(S);
Push(S,T); // 根指针进栈
while(!StackEmpty(S)){
while(GetTop(S,p)&&p) Push(S, p->lchild); //代码标记1
Pop(S,p); //代码标记2
if(!StackEmpty(S)){
Pop(S,p);
if(!Visit(p->data)) return ERROR; //代码标记4
Push(S,p->rchild); //代码标记5
}
}
return OK;
}