首页 > 代码库 > 好久没更新了,哪里不对!更新二叉树的非递归遍历

好久没更新了,哪里不对!更新二叉树的非递归遍历

#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;        }    }}