现在的位置: 首页 > 综合 > 正文

npostorder

2014年02月20日 ⁄ 综合 ⁄ 共 615字 ⁄ 字号 评论关闭

/*
 * LRD
 */
typedef struct
{
    int tag;
    BinTree t;
}Elem;

void nPostOrder(BinTree t)
{
    Stack s;
    BinTreeNode * p = t;
    Elem stnode;
    if(t == NULL) return;
    s = CreateEmptyStack;
    do{
        // first push
        while(p!=NULL)
        {
            stnode.tag = 1;
            stnode.t = p;
            push(s, stnode);
            p = leftChild(p);
        }
        // pop
        while(!isEmptyStack(s))
        {
            stnode = top(s);
            pop(s);
            p = stnode.t;
        }
        // second push
        if(stnode.tag == 1)
        {
            stnode.tag = 2;
            push(s, stnode);
            p = rightChild(p);
            break;
        }
        else visit(root(p));
    }while(!isEmptyStack);
}

【上篇】
【下篇】

抱歉!评论已关闭.