#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
#define OK 1
#define ERROR 0
#define max 100
typedef char TElemType;
/* 二叉树节点的存储类型 */
typedef struct BiTNode //define stricture BiTree
{ TElemType data;
struct BiTNode *lchild,*rchild;
boarder
}BiTNode, *BiTree;
int BiTreeEmpty(BiTree T)
美国魔法学校翻译公司报价{
if(T == NULL)
return 0;
el
return 1;
}
/*建立二叉树*/
int CreateBiTree(BiTree &T) //createBiTree() sub-function
{ TElemType ch;
cin>>ch;
if(ch=='/') T=NULL;
el
{ if(!(T=(BiTNode *)malloc(sizeof(BiTNode))))
{ cout<<"Overflow!"; //no alloction
return (ERROR);
}
T->data=ch;
CreateBiTree(T->lchild); //create lchild
CreateBiTree(T->rchild); //create rchild
}
return (OK);
} //CreateBiTree() end
/*前序遍历二叉树的递归算法*/
int PreOrderTraver(BiTree T) //PreOrderTravers sub-function
{ if(T)
{ cout<<T->data<<"->"; //visite T
if (PreOrderTraver(T->lchild)) //traver lchild
if (PreOrderTraver(T->rchild)) //traver rchild
return (OK);
return (ERROR);
} //if end
el
return (OK);
}
int InOrderTraver(BiTree T) //InOrderTraver sub-function
{ if(T)
{ if (InOrderTraver(T->lchild)) //traver lchild
{ cout<<T->data<<"->"; //visite T
if(InOrderTraver(T->rchild)) //traver rchild
return (OK);
}
return (ERROR);
国内的英语培训机构
} //if end
el
return (OK);
} //InOrderTraver() end
int PostOrderTraver(BiTree T) //PostOrderTraver() sub-function
{ if(T)
{ if (PostOrderTraver(T->lchild)) //traver lchild
if(PostOrderTraver(T->rchild)) //traver rchild
{ cout<<T->data<<"->"; //visite T
mannareturn (OK);
}
return (ERROR);
}
el
return (OK);
} //PostOrderTraver() end
void LevleOrder(BiTree T){
BiTree Queue[max],p;
int front=0,rear=0;
if(T)
{Queue[rear++]=T;
while(front!=rear){
p=Queue[front++];cesar chavez
printf("%c->",p->data);
if(p->lchild!=NULL)
Queue[rear++]=p->lchild;
if(p->rchild!=NULL)
Queue[rear++]=p->rchild;}
}
}
void DestoryBiTree(BiTree &T)
{
if(BiTreeEmpty(T))
{
DestoryBiTree(T->lchild);
DestoryBiTree(T->rchild);
free(T);
四级原题
}
}
changes in my hometownint main(){
printf("-------------------------------\n");
printf("董文来:实验一(1)\n");
printf("-------------------------------\n");
printf("----------二叉链表作存储结构---------\n");
BiTree T;
printf("请输入初始二叉树(按先序):");
CreateBiTree(T);
printf("先序遍历为:");
PreOrderTraver(T);
cout<<endl;
printf("中序遍历为:");
InOrderTraver(T);
cout<<endl;
printf("后序遍历为:");
PostOrderTraver(T);
packages是什么意思
cout<<endl;
printf("层序遍历为:");
LevleOrder(T);
cout<<endl;
DestoryBiTree(T);
return 0;
雅思听力高频词汇}