#include<iostream>
using namespace std;
#define MAXSIZE 500
typedef struct tree{char data;struct tree *lchild;struct tree *rchild;}tree,*Tree;//非递归算法的深度遍历
//不利用系统的递归栈,自己自定义栈,用来实现先序遍历
//先将右孩子入栈,在将左孩子入栈,因为栈是后进先出
void preOrderDepth(Tree t){Tree stackTree[MAXSIZE];int top = -1;Tree p;if(t != NULL){//先将头指针入栈stackTree[++top] = t;//如果栈不为空,则先出栈元素,在将元素的右孩子入栈,在入栈左孩子while(top != -1){p = stackTree[top--];//访问节点cout<<p->data<<endl;if(p->rchild != NULL){stackTree[++top] = p->rchild;} if(p->lchild != NULL){stackTree[++top] = p->lchild;}}}
}