BTREE - else p=p->right; }...

Info iconThis preview shows pages 1–2. 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; s 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++) { y=x[i]; q=ptree; p=q; while(p!=NULL) { q=p; if(y<p->data) p=p->left;
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: else p=p-&gt;right; } if(y&lt;q-&gt;data) 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(); }...
View Full Document

This note was uploaded on 10/25/2010 for the course CMPN SEM4 taught by Professor Thakur during the Spring '07 term at University of Mumbai.

Page1 / 2

BTREE - else p=p-&amp;amp;gt;right; }...

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

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