中序遍历非递归遍历算法
void InOrderTraversal(BinTree BT)
{
BinTree T=BT;
Stack S = CreatStack(Maxsize);
while(T || !isempty(s))
{
while(T)
{
push(S,T);
T=T->Left;
}
if(!isempty(s))
{
T=Pop(s);
printf("%5d",T->Data);
T=T->Right;
}
}
}
先序遍历的非递归遍历算法
void InOrderTraversal(BinTree BT)
{
BinTree T=BT;
Stack S = CreatStack(Maxsize);
while(T || !isempty(s))
{
while(T)
{
printf("%5d",T->Data);
push(S,T);
T=T->Left;
}
if(!isempty(s))
{
T=Pop(s);
T=T->Right;
}
}
}
后序遍历的非递归遍历算法
``
void PostOrderTraversal(BinTree BT) {
BinTree T = BT, PrePop = NULL; //PrePop记录上一个Pop出来的结点
Stack S = CreatStack(MaxSize);
while (T || !IsEmpty(S)) {
while (T) { //一直向左将结点压入堆栈
Push(S, T);
T = T->Left;
}
//将Pop的过程改为循环
while (!IsEmpty(S)) { //后序遍历有两种情况可以Pop该结点
T = Pop(S);
i