二叉树后序遍历<非递归>

    while(curr) {
        //print left most node, notice the root node
        if ((curr->left && curr->left->visited == false) || (curr->right && curr->right->visited == false)) {
            while (curr->left || curr->right) {
                if (curr->left && curr->left->visited == false) {
                    curr = curr->left;
                    treeStack.push_back(curr);
                    continue;
                }
                curr = curr->right;
                treeStack.push_back();
            }
            continue;
        }
        printTree(curr);
        curr->visited = true;
        curr = treeStack.pop_back();
    }
posted @ 2012-05-10 22:51  Jack204  阅读(441)  评论(0编辑  收藏  举报