c语言实验-树讲述
1、验证基于顺序存储的二叉树的基本操作。
#include iostream.h
#define NULL 0
#define MaxSize 100
typedef struct sqtree
{
char data[MaxSize];
int num;
}SqTree;
void InitTree(SqTree *t)
{
t = new SqTree;
t-num = 0;
}
void CreaTree(SqTree *t, char tr[])
{
for (int i = 0; tr[i] != \0; i ++)
{
t-data[i] = tr[i];
t-num ++;
}
}
void DispTree(SqTree *t)
{
for (int i = 0; i t-num; i ++)
{
coutt-data[i];
}
coutendl;
}
void FindTNode(SqTree *t, char x)
{
for (int i = 0; i t-num; i ++)
{
if (x == t-data[i])
{
if (i = t-num/2)
{
cout值为x的结点为叶子结点,其双亲为:;
coutt-data[(i+1)/2]
原创力文档

文档评论(0)