BTREE - setleft(q,y); else setright(q,y); } } void...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#include<stdio.h> #include<conio.h> /* RISHI AGARWAL          btree  SORT    ROLL NO 02    SE CMPN A */ struct btree {  int data;  struct btree *left;  struct btree *right; }; struct btree *ptree,*q,*p; struct btree * maketree(int a) {  struct btree *v;  v=(struct btree *)malloc(sizeof(struct btree));  v->data=a;  v->left=NULL;  v->right=NULL;  return v; } void setleft(struct btree *pl,int z) {  pl->left=maketree(z); } void setright(struct btree *pl,int z) {  pl->right=maketree(z); } void btreesort(int x[],int n) {  int i,y;  ptree=maketree(x[0]);  for(i=1;i<n;i++)  {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
  y=x[i];   q=ptree;   p=q;   while(p!=NULL)   {    q=p;    if(y<p->data)    p=p->left;    else    p=p->right;   }   if(y<q->data)
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: setleft(q,y); else setright(q,y); } } void intrav(struct btree *pl) { if(pl!=NULL) { intrav(pl-&gt;left); printf(&quot;%d &quot;,pl-&gt;data); intrav(pl-&gt;right); } } void main() { int n,i,a[10]; clrscr(); printf(&quot;Enter the no of data:&quot;); scanf(&quot;%d&quot;,&amp;n); printf(&quot;Enter the nos&quot;); for(i=0;i&lt;n;i++) scanf(&quot;%d&quot;,&amp;a[i]); //Displaying List printf(&quot;List:&quot;); for(i=0;i&lt;n;i++) printf(&quot;%d &quot;,a[i]); // Sort btreesort(a,n); //Displaying Sorted List printf(&quot;\nInorder Traversal:&quot;); intrav(ptree); getch(); } Enter the no of data:5 Enter the nos3 4 2 5 1 List:3 4 2 5 1 Inorder Traversal:1 2 3 4 5...
View Full Document

Page1 / 3

BTREE - setleft(q,y); else setright(q,y); } } void...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online