帮我写此程序的注释 越细越好!可追!!

来源:百度知道 编辑:UC知道 时间:2024/08/22 01:06:33
#include <stdio.h>
#include <malloc.h>

typedef struct BiTnode
{
int data;
struct BiTnode *lchild,*rchild;
}BiTnode,*BiTree;

BiTree search_tree(BiTree T,int keyword,BiTree *father)
{
BiTree p;
*father = NULL;
p = T;
while (p && p->data!=keyword)
{
*father = p;
if (keyword < p->data)
p = p->lchild;
else
p = p->rchild;
}
return p;
}

BiTree creat_tree(int count)
{
BiTree T,p;
int i = 1;
while (i <= count)
{
if (i == 1)
{
p = (BiTnode *)malloc(sizeof(BiTree));
if (!p)
return NULL;
T = p;
scanf("%d",&p->data);
p->lchild = p->rchild = NULL;
i++;
}
else
{
int temp;
scanf("%d",&temp);
search_tree(T,temp,&p);
if (temp < p->data)
{
p->lchild = (Bi

#include <stdio.h>
#include <malloc.h>
typedef struct BiTnode
{
int data;
struct BiTnode *lchild,*rchild;
}BiTnode,*BiTree;

BiTree search_tree(BiTree T,int keyword,BiTree *father) //查找二叉树中的元素。
{
BiTree p;
*father = NULL;
p = T;
while (p && p->data!=keyword)
{
*father = p;
if (keyword < p->data)
p = p->lchild;
else
p = p->rchild;
}
return p;
}

BiTree creat_tree(int count) //创建一棵二叉树
{
BiTree T,p;
int i = 1;
while (i <= count)
{
if (i == 1)
{
p = (BiTnode *)malloc(sizeof(BiTree));
if (!p)
return NULL;
T = p;
scanf("%d",&p->data);
p->lchild = p->rchild = NULL;
i++;
}
else
{
int temp;
scanf("%d",&temp);
search_tree(T,temp,&p);
if (temp < p->data)
{