BINTREE - printf("%s...

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> #include<string.h> # #define max 10 # struct node { struct node *left; char data[5]; struct node *right; }; } int lt[max],rt[max]; char arr[max][5]; c struct node* maketree(int index) { struct node *temp; temp=NULL; if(index!=-1) { temp=(struct node *)malloc(sizeof(struct node)); temp->left=maketree(lt[index]); strcpy(temp->data,arr[index]); temp->right=maketree(rt[index]); } return temp; } void inorder(struct node *root) { if(root!=NULL) { inorder(root->left); printf("%s ",root->data); inorder(root->right); } } void preorder(struct node *root) { if(root!=NULL) { printf("%s ",root->data); preorder(root->left); preorder(root->right); } } void postorder(struct node *root) { if(root!=NULL) { postorder(root->left); postorder(root->right);
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: printf(&quot;%s &quot;,root-&gt;data); } } void main() { int l,r,c=1,i=0,j; char d[5]; struct node *root; root=NULL; clrscr(); while(c==1) { c=0; printf(&quot;Enter a character &amp; left,right data pos:&quot;); scanf(&quot;%s%d%d&quot;,&amp;d,&amp;l,&amp;r); strcpy(arr[i],d); lt[i]=l; rt[i]=r; i++; printf(&quot;to add more press 1 else 0:&quot;); scanf(&quot;%d&quot;,&amp;c); } for(j=0;j&lt;i;j++) printf(&quot;%s &quot;,arr[j]); printf(&quot;\n&quot;); for(j=0;j&lt;i;j++) printf(&quot;%d &quot;,lt[j]); printf(&quot;\n&quot;); for(j=0;j&lt;i;j++) printf(&quot;%d &quot;,rt[j]); printf(&quot;\n&quot;); root=maketree(0); printf(&quot;Tree in Inorder Form\n&quot;); inorder(root); printf(&quot;\nTree in Preorder Form\n&quot;); preorder(root); printf(&quot;\nTree in Postorder Form\n&quot;); postorder(root); getch(); }...
View Full Document

Page1 / 2

BINTREE - printf(&amp;amp;quot;%s...

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