#include <stdio.h>
#include <string.h>
#include <iostream>
#include <stack>
#include <queue>
using namespace std;
#define MAXSIZE 20
typedef struct bnode
{
char data;
struct bnode *lchild,*rchild;
}BNode,*bitree;
bitree pre_create()//创建二叉树
{
bitree bt;
char ch;
ch=getchar();
if(ch==' ')
return NULL;
else
{
bt=new BNode[sizeof(BNode)];
bt->data=ch;
bt->lchild=pre_create();
bt->rchild=pre_create();
}
}
void pre_order(bitree bt)//非递归先序遍历
{
stack<bitree> s;
bitree p=bt;
while(p||!s.empty())
{
while(p)
{
s.push(p);
cout<<p->data<<" ";
p=p->lchild;
}
if(!s.empty())
{
二叉树的先序、中序、后序的非递归遍历(分别用两个栈和一个带标志位的栈两种方法去做)和层次遍历
最新推荐文章于 2025-03-22 14:45:40 发布