主题:[讨论]十万火急!请哪位大狭帮帮我修改下!
给定一关键字序列(45,24,53,45,12,24,90),请生成一二叉排序树T,并实现插入一关键字为48的结点.
#include "stdio.h"
#define null 0
typedef int keyType;
typedef struct {
keyType key;
}ElemType;
typedef struct BiTNode
{
ElemType data;
struct BiTNode * lchild;
struct BiTNode * rchild;
}BiTNode,*BiTree;
BiTree T;
Creat(int a[])
{
BiTree p;
BiTree q;
int i=0;
T=null;
if(!T) {
T=(BiTree)malloc(sizeof(BiTNode));
T->data.key=a[i];
i++;
q=T;
}
else
for(i=1;i<7;i++)
{p=(BiTree)malloc(sizeof(BiTNode));
p->data.key=a[i];
q=Search(T,a[i]);
if(q==0) continue;
else {
if(q->data.key>a[i]) q->lchild=p;
else q->rchild=p;
}
}
}
Bitree Search(Bitree tt,KeyType k)
{
if(tt->data.key==k) return 0;
else if(tt->data.key>k)
{
if(tt->lchild==null) return tt;
else return Search(tt->lchlid,k);
}
else if(tt->data.key<k)
{
if(tt->lchild==null) return tt;
return Search(tt->rchlid,k);
}
main()
{
int aa[10]={45,24,53,45,12,24,90};
Creat(aa);
}
#include "stdio.h"
#define null 0
typedef int keyType;
typedef struct {
keyType key;
}ElemType;
typedef struct BiTNode
{
ElemType data;
struct BiTNode * lchild;
struct BiTNode * rchild;
}BiTNode,*BiTree;
BiTree T;
Creat(int a[])
{
BiTree p;
BiTree q;
int i=0;
T=null;
if(!T) {
T=(BiTree)malloc(sizeof(BiTNode));
T->data.key=a[i];
i++;
q=T;
}
else
for(i=1;i<7;i++)
{p=(BiTree)malloc(sizeof(BiTNode));
p->data.key=a[i];
q=Search(T,a[i]);
if(q==0) continue;
else {
if(q->data.key>a[i]) q->lchild=p;
else q->rchild=p;
}
}
}
Bitree Search(Bitree tt,KeyType k)
{
if(tt->data.key==k) return 0;
else if(tt->data.key>k)
{
if(tt->lchild==null) return tt;
else return Search(tt->lchlid,k);
}
else if(tt->data.key<k)
{
if(tt->lchild==null) return tt;
return Search(tt->rchlid,k);
}
main()
{
int aa[10]={45,24,53,45,12,24,90};
Creat(aa);
}