如何建立个二叉树

来源:百度知道 编辑:UC知道 时间:2024/05/29 19:16:15
1建立一棵2叉树
2用递归法遍历2叉树,打印遍历的序列(随便一种遍历,请写好用哪一种)
3用层次遍历的方法遍历该2叉树

输入二叉数的各个结点值,按二叉链表的存储形式建立该二叉数,然后输出先序遍历、中序遍历和层次遍历的序列。
实现函数:
#include<stdio.h>
#include<math.h>
#define NULL 0
#define OK 1
#define ERROR 0
/*-----------------------------------------------------------------*/
typedef struct BiTNode{
int data;
struct BiTNode *lchild,*rchild;
}BiTNode,*BiTree;
/*-----------------------------------------------------------------*/
typedef struct{
BiTNode *base[100];
int front;
int rear;
}sq;
/*-----------------------------------------------------------------*/
sq initqueue()
{ sq q; int i;
for(i=0;i<100;i++) {
q.base[i]=NULL;
q.front=q.rear=0;}
return q;}
/*-----------------------------------------------------------------*/
int PrintElement(char e){
printf("%c",e);
return OK;
}
/*-----------------------------------------------------------------*/
BiTree createTree()
{