跪求数据结构编程

来源:百度知道 编辑:UC知道 时间:2024/05/15 06:36:12
分类二叉树的构建

1、预习要求:分类二叉树结构定义。
2、实验目的:
(1)了解分类二叉树结构概念;
(2)理解分类二叉树构建过程;
(3)掌握分类二叉树构建算法程序。
3、实验内容及要求:
(1)建立包含10个结点的分类二叉树(树结构和数据元素的值由自己设定);
(2)完成分类二叉树中序遍历程序;
(3)给出程序和遍历程序的结果。

为了能在叶子节点返回,我们得多添加叶子节点,使所有的叶子节点都为NULL,他们的直为'?'.
运行该程序,按先序输入ABD??EG???CFH??I?J???+回车
输出first:ABDEGCFHIJ middle:DBGEAHFIJC
#include <stdio.h>
#include <stdlib.h>
#define NULLKEY '?'

typedef struct btnode
{
char data;
struct btnode *lchild,*rchild;
}btnode,*bitree;
bitree preCreateBitree(bitree &root)
{
char ch;
scanf("%c",&ch);
if(ch==NULLKEY)
{
root=NULL;
return(root);
}
else
{
root=(bitree)malloc(sizeof(btnode));
root->data=ch;
preCreateBitree(root->lchild);
preCreateBitree(root->rchild);
return(root);
}
}

void fsearch(bitree root)
{
if(root==NULL)
return ;
else
{
printf("%c",root->data); //先序遍历每个结点的值
fsearch(root->lchild);
fsearch(root->rchild);
}
}

void msearch(bi