代码如下:
#define n 10
typedef struct node{int key;struct node *lchild,*rchild;}bitree;
void bstinsert(bitree *&bt,int x)
{
if(bt==0)
{
bt=(struct node *)malloc(sizeof(struct node));
bt->key=x;
bt->lchild=bt->rchild=0;
}else if(bt->key>x)
{
bstinsert(bt->lchild,x);
}else
{
bstinsert(bt->rchild,x);
}
}
void creatbtree(bitree *&bt)
{
int i;
for(i=0;i<n;i++)
{
bstinsert(bt,random(100));
}
}