- 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);
- }