急需编写”二叉排序树的查找和添加” c语言程序

来源:百度知道 编辑:UC知道 时间:2024/04/24 19:08:58
我急切的需要程序的原代码,谢谢!

typedef stuct node{
int key;
struct nod *lchild,*rchild;
}BSTree;
void InsertBST(BSTree *&bt,int k)
{
BSTree *f,*p=bt;
while(p!=NULL)
{if (p->key==k)return;
f=p;
if(p->key>k)p=p->lchild;
else p=p->rchild;
}

p=(BSTree *)malloc(sizeof(BSTree));
p->key=k;p->lchild=p->rchild=NULL;
if(bt==NULL) bt=p;
else if(k<f->key)f->lchild=p;
else f->rchild=p;
}

BSTee *creatBST(int A[],int n)
{BSTree *bt=NULL;
int i=0;
while(i<n){
InsertBST(bt,A[i]);
i++
}
return bt;
}

void *delnod(BSTree *&bt,BSTree *p,BSTree *q)
{
BSTree *s,*r;
if(bt->lchild==NULL){
if(p==bt)
bt=p->rchild;
else if (q->lchild==pp)
q->lchild=p->rchild;
else
q->rchild=p->rchild
}
esle if (p->rchild=