丽江木家苑客栈:关于二叉树(中序,层序,顺序,静态,传地址)

来源:百度文库 编辑:高考问答 时间:2024/04/28 10:01:23
一、题目
以字母为元素,按中序顺序存储元素,按层序顺序存储元素的下标,实现二叉树的基本操作:输出、输入、求树深、求叶子数、前序、中序、后序、层序。
要求:①对于需要回传的参数,把实参的地址传给形传;②能在TC2环境下执行。

二、概要设计
1.存储结构
中序 前序
n d[0] … d[n-1] … a[0] … a[n-1] …
结点数 元素 … 元素 … 下标 … 下标 …
typedef struct{
int n;/*结点数*/
DataType d[MAX];/*中序*/
int a[MAX];/*后序*/
}BiTree;
2.基本操作
⑴void Puts(BiTree T)--按广义表形式输出二叉树。
⑵void Gets(BiTree *T,char **s)--由广义表形式串创建二叉树。
⑶void Depth(BiTree T,int *i)--求树深。
⑷void Leaf(BiTree T,int *i)--求叶子数。
⑸void FPrint(BiTree T)--前序。
⑹void MPrint(BiTree T)--中序。
⑺void LPrint(BiTree T)--后序。
⑻void LePrint(BiTree T)--层序。
跪求详细设计!!!
跪求详细设计!!!
跪求详细设计!!!

#include <stdio.h>
struct tree
{ char data;
int prt;
int lch;
int rch;
}
a[10]
main() {
a[1]={'a',0,2,3};
a[2]={'b',1,4,5};
a[3]={'c',1,0,0};
a[4]={'d',2,0,0};
a[5]={'e',2,0,0};
a[6]={'f',3,0,0};
a[7]={'g',3,0,0};
a[8]={'h',4,0,0};
a[9]={'i',4,0,0};
preorder(1);
}

preorder(int i)
{if i!=0
{
printf("%c",a[i].data);
preorder(a[i].lch);
preorder(a[i].rch) ;
}
}