#include <iostream> #include <stack> using namespace std; typedef struct Node { Node* lchild; Node* rchild; int data; }BNode,BTree; void visit(Node*); void inorder(BTree *root) { BNode * p = root; stack<Node*> s; if(p||!s.empty()) { s.push(p); p = p->lchild; } else { p = s.top(); visit(p); s.pop(); p = p ->rchild; } } void postorder(BTree *root) { BNode* p = root; BNode* flag = NULL; stack<Node*>s; if(root||!s.empty()) { s.push(root); p = p ->lchild; } else { p = s.top(); if(p->rchild&&p->rchild != flag) { p = p->rchild; s.push(p); p = p->lchild; } else { visit(p); s.pop(); flag = p; p = p->lchild; } } }
好久没更新了,哪里不对!更新二叉树的非递归遍历,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/cliviazhou/p/3849902.html