二叉树的遍历的完整代码是什么
的有关信息介绍如下:二叉树遍历代码
#include"iostream.h"
#include"stdlib.h"
#include"stdio.h"
#include
using namespace std;
#define NULL 0
#define OK 1
#define OVERFLOW -1
typedef int Status;
typedef struct node
{
char data;
struct node *lchild;
struct node *rchild;
}*bitree;
int k=0;
int depth(bitree T)//树的高度
{
if(!T)return 0;
else
{
int m=depth(T->lchild); int n=depth(T->rchild); return (m>n?m:n)+1;
}
}
//先序,中序 建树
struct node *create(char *pre,char *ord,int n) {
struct node * T;
int m;
T=NULL;
if(ndata=*pre;
T->lchild=T->rchild=NULL; while(ord[m]!=*pre)
m++;
T->lchild=create(pre+1,ord,m);
T->rchild=create (pre+m+1,ord+m+1,n-m-1); return T;
}
}
//中序递归遍历
void inorder(struct node *T)
{
if(!T)
return;
else
{
inorder(T->lchild );
coutrchild );
}
}
void inpre(struct node *T)
{
if(!T)
return;
else
{
coutlchild );
inpre(T->rchild );
}
}
void postorder(struct node *T)
{
if(!T)
return;
else
{
postorder (T->lchild );
postorder (T->rchild );
cout