?? ch5_9.c
字號:
#include <stdio.h>
#include <alloc.h>
typedef struct node
{ int data;
struct node *lchild,*rchild;
}JD;
JD *insertbst(JD *r,int x)
{ JD *p,*q,*s;
s=(JD *)malloc(sizeof(JD));
s->data=x; s->lchild=s->rchild=NULL;
q=NULL;
if(r==NULL) { r=s; return(r);}
p=r;
while(p!=NULL)
{ q=p;
if(x<p->data)
p=p->lchild;
else
p=p->rchild;
}
if(x<q->data)
q->lchild=s;
else
q->rchild=s;
return(r);
}
void inorder(JD *bt)
{ if(bt!=NULL)
{ inorder(bt->lchild);
printf("%d\t",bt->data);
inorder(bt->rchild);
}
}
void main()
{ static int key[]={10,18,3,8,12,2,7,3};
JD *head=NULL;
int i,n=8;
for(i=0;i<n;i++)
head=insertbst(head,key[i]);
inorder(head);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -