编程:二叉排序树,必须实现构建,查找,插入,删除四个基本操作

来源:百度知道 编辑:UC知道 时间:2024/05/27 08:03:02
简单的问题,可是我不会,还要请高手帮帮忙,马上就要答辩了啊~~
辛苦了啊!

#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 = (BiTnode *)malloc(sizeof(BiTnode));
if (