首页 > 试题广场 >

在链式存储结构上建立一棵二叉排序树。

[问答题]
在链式存储结构上建立一棵二叉排序树。
在每个节点分别添加左孩子节点引用和右孩子引用,并给所有节点的引用赋值即可。
发表于 2018-06-09 18:54:30 回复(0)

#define n 10

typedef struct node{int key; struct node *lchild,*rchild;}bitree;

void bstinsert(bitree *&bt,int key)

{

if (bt==0){bt=(bitree *)malloc(sizeof(bitree)); bt->key=key;bt->lchild=bt->rchild=0;}

else if (bt->key>key) bstinsert(bt->lchild,key); else bstinsert(bt->rchild,key);

}

void createbsttree(bitree *&bt)

{

int i;

for(i=1;i<=n;i++) bstinsert(bt,random(100));

}
发表于 2017-05-16 23:23:13 回复(1)