二叉排序树的建立,中序遍历二叉排序树的建立,中序遍历 #include #include #include using namespace std; typedef int datatype; typedef struct node { datatype key; struct node *lchild,*rchild; }bsnode; typedef bsnode *bstree; void insertbstree(bstree *t,datatype x) { bstree f,p; p = *t; //coutk...
key))//
// return;
f = p;
if(x < p->key)
p = p ->lchild;
else
p = p ->rchild;
//f = p;
}
//f = p;
p =(bstree)malloc(sizeof(bsnode));
p->key = x;
p->lchild=p->rchild=NULL;
if(*t == NULL)
*t = p;
else
{
if(x < (f->key))
f->lchild = p;
else
f->rchild = p;
}
}
bstree creatbstree(bstree t) {
datatype key;
//scanf("%d",&key);
cin>>key;
while(key != -1)
{
insertbstree(&t,key);
//scanf("%d",&key);
cin>>key;
}
return t;
}
void inorder(bstree t) {
if (t)
{
inorder(t->lchild);
printf("%d ",t->key);
inorder(t->rchild);
}
}
int main(void)
{
bstree t = NULL,p;
//cout<