首页 > 这是我写的非递归先序遍历程序!可是我无法理解他在走完右边,遇到NULL后的操作,谁能解释一下。

这是我写的非递归先序遍历程序!可是我无法理解他在走完右边,遇到NULL后的操作,谁能解释一下。

void PreOrderTraversal(BinTree BT)
{
    BinTree T = BT;
    stack *S = CreatStack();
    while (T || !IsEmpty(S))   /*可以理解成在堆栈有值的时候,链路可能到尽头*/
    {
        while (T)
        {
            Push(T, S);
            printf("%5d", T->Data);  /*先序*/
            T = T->Left;
        }
        if (!IsEmpty(S))
        {
            T = Pop(S);
            T = T->Right;
        }
    }
}
【热门文章】
【热门文章】