Binary tree

306 views
246 views

Published on

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
306
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Binary tree

  1. 1. #include<stdio.h> printf("n***MENU***");#include<conio.h> printf("n1.CREATEn2.PRE-ORDER");#include<alloc.h> printf("n3.IN-ORDERn4.POST-void create(struct node *); ORDERn5.EXIT");void in_order(); printf("nPLease Enter the Choice...");void pre_order(); scanf("%d",&ch);void post_order(); switch(ch)struct node {{ case 1:root=NULL; int data; create(root);break; struct node *left,*right; case 2:pre_order();break;}*root=NULL,*New,*temp,*p,*stack[20]; case 3:in_order();break;int top=-1,flag[20],item; case 4:post_order();break;char c; case 5:exit(0); default: printf("nInvalid choice...");void main() }{ }while(ch!=5); int ch,e; getch(); clrscr(); } do {
  2. 2. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL)//Is It first node? if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ",t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("nDo you want add Another(y/n)..."); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); } } } } else{ New=(struct node *) malloc (sizeof (struct node));
  3. 3. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL)//Is It first node? if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ",t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("nDo you want add Another(y/n)..."); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); } } } } else{ New=(struct node *) malloc (sizeof (struct node));
  4. 4. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL)//Is It first node? if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ",t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("nDo you want add Another(y/n)..."); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); New } } } } else{ New=(struct node *) malloc (sizeof (struct node));
  5. 5. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); 100 struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ",t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("nDo you want add Another(y/n)..."); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 New } } } } else{ New=(struct node *) malloc (sizeof (struct node));
  6. 6. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ",t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("nDo you want add Another(y/n)..."); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 New } } } } else{ New=(struct node *) malloc (sizeof (struct node));
  7. 7. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ",t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("nDo you want add Another(y/n)..."); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 New } } root } } else{ New=(struct node *) malloc (sizeof (struct node));
  8. 8. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ",t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); y { if(ch==y) s=t; create(t->right); create(root); 100 New } } root } } else{ New=(struct node *) malloc (sizeof (struct node));
  9. 9. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ",t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 New } } root } } else{ New=(struct node *) malloc (sizeof (struct node));
  10. 10. void create(struct node *t) t = 100 New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ",t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } } } else{ New=(struct node *) malloc (sizeof (struct node));
  11. 11. void create(struct node *t) t = 100 New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ",t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } } } else{ New=(struct node *) malloc (sizeof (struct node));
  12. 12. void create(struct node *t) t = 100 New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ",t->data); if(c==l || c==L‘) scanf("%c",&c); l s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } } } else{ New=(struct node *) malloc (sizeof (struct node));
  13. 13. void create(struct node *t) t = 100 New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } } } else{ New=(struct node *) malloc (sizeof (struct node));
  14. 14. void create(struct node *t) t = 100 New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else{ New=(struct node *) malloc (sizeof (struct node));
  15. 15. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else{ New=(struct node *) malloc (sizeof (struct node));
  16. 16. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else{ New=(struct node *) malloc (sizeof (struct node));
  17. 17. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); 50 struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else 50 New{ New=(struct node *) malloc (sizeof (struct node));
  18. 18. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else 50 New{ New=(struct node *) malloc (sizeof (struct node));
  19. 19. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else 50 New{ New=(struct node *) malloc (sizeof (struct node));
  20. 20. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else 50 New{ New=(struct node *) malloc (sizeof (struct node));
  21. 21. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); y { if(ch==y) s=t; create(t->right); create(root); 100 root } } } } else 50{ New=(struct node *) malloc (sizeof (struct node));
  22. 22. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } } } else 50{ New=(struct node *) malloc (sizeof (struct node));
  23. 23. void create(struct node *t) t = 100 New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } } } else 50{ New=(struct node *) malloc (sizeof (struct node));
  24. 24. void create(struct node *t) t = 100 New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } } } else 50{ New=(struct node *) malloc (sizeof (struct node));
  25. 25. void create(struct node *t) t = 100 New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); r s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } } } else 50{ New=(struct node *) malloc (sizeof (struct node));
  26. 26. void create(struct node *t) t = 100 New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } } } else 50{ New=(struct node *) malloc (sizeof (struct node));
  27. 27. void create(struct node *t) t = 100 New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else 50{ New=(struct node *) malloc (sizeof (struct node));
  28. 28. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else 50{ New=(struct node *) malloc (sizeof (struct node));
  29. 29. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else 50{ New=(struct node *) malloc (sizeof (struct node));
  30. 30. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); 60 struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else 50 60 New{ New=(struct node *) malloc (sizeof (struct node));
  31. 31. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else 50 60 New{ New=(struct node *) malloc (sizeof (struct node));
  32. 32. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else 50 60 New{ New=(struct node *) malloc (sizeof (struct node));
  33. 33. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else 50 60 New{ New=(struct node *) malloc (sizeof (struct node));
  34. 34. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); n { if(ch==y) s=t; create(t->right); create(root); 100 root } } s } } else 50 60 New{ New=(struct node *) malloc (sizeof (struct node));
  35. 35. void create(struct node *t) t = NULL New->left=New->right=NULL;{ printf("nEnter the Element..."); char ch; scanf("%d",&New->data); struct node *s; if(root==NULL) if(t!=NULL) root=New; { else printf("nWhether you want to insert at { Left or Rigth( L/R) of %d ", t->data); if(c==l || c==L‘) scanf("%c",&c); s->left=New; if(c==l|| c==L‘) else { s->right=New; s=t; create(t->left); } } printf("Do you want add Another (y/n)"); else scanf("%c",&ch); { if(ch==y) s=t; create(t->right); create(root); 100 root } } } } else 50 60{ New=(struct node *) malloc (sizeof (struct node));
  36. 36. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) 0 { top = -1 finish = 0 p=stack[top]; top--;
  37. 37. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p p=root; printf("nInorder Traversal is...n"); 50 60 do { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top 0 NULL { finish = 0 p=stack[top]; top--;
  38. 38. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p p=root; printf("nInorder Traversal is...n"); 50 60 do { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top0 NULL { finish = 0 p=stack[top]; top--;
  39. 39. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); p 50 60 do { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } top1 100 if(top!=0) 0 NULL { finish = 0 p=stack[top]; top--;
  40. 40. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); p 50 60 do { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } top1 100 if(top!=0) 0 NULL { p=stack[top]; finish = 0 top--;
  41. 41. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; top2 50 } 1 100 if(top!=0) 0 NULL { finish = 0 p=stack[top]; top--;
  42. 42. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; top2 50 } 1 100 if(top!=0) 0 NULL { finish = 0 p=stack[top]; top--;
  43. 43. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; top2 50 } 1 100 if(top!=0) 0 NULL { finish = 0 p=stack[top]; top--;
  44. 44. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); p 50 60 do { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } top1 100 if(top!=0) 0 NULL { finish = 0 p=stack[top]; top--;
  45. 45. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } top1 100 if(top!=0) 0 NULL { finish = 0 p=stack[top]; 50 100 top--;
  46. 46. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } top1 100 if(top!=0) 0 NULL { finish = 0 p=stack[top]; 50 100 top--;
  47. 47. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } top1 100 if(top!=0) 0 NULL { finish = 0 p=stack[top]; 50 100 top--;
  48. 48. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } top1 100 if(top!=0) 0 NULL { finish = 0 p=stack[top]; 50 100 top--;
  49. 49. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p p=root; printf("nInorder Traversal is...n"); 50 60 do { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top0 NULL { finish = 0 p=stack[top]; 50 100 top--;
  50. 50. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 p do { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top0 NULL { finish = 0 p=stack[top]; 50 100 top--;
  51. 51. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 p do { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top0 NULL { finish = 0 p=stack[top]; 50 100 top--;
  52. 52. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 p do { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top0 NULL { finish = 0 p=stack[top]; 50 100 top--;
  53. 53. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } top1 60 if(top!=0) 0 NULL { finish = 0 p=stack[top]; 50 100 top--;
  54. 54. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } top1 60 if(top!=0) 0 NULL { finish = 0 p=stack[top]; 50 100 top--;
  55. 55. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } top1 60 if(top!=0) 0 NULL { finish = 0 p=stack[top]; 50 100 top--;
  56. 56. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 p do { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top0 NULL { finish = 0 p=stack[top]; 50 100 top--;
  57. 57. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top0 NULL { finish = 0 p=stack[top]; 50 100 60 top--;
  58. 58. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top0 NULL { finish = 0 p=stack[top]; 50 100 60 top--;
  59. 59. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top0 NULL { finish = 0 p=stack[top]; 50 100 60 top--;
  60. 60. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top0 NULL { finish = 0 p=stack[top]; 50 100 60 top--;
  61. 61. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top0 NULL { finish = 1 p=stack[top]; 50 100 60 top--;
  62. 62. void in_order() printf("%d ",p->data);{ p=p->right; int finish=0; } if(root==NULL) else { finish=1; printf("nTree is Empty...");return; }while(finish==0); } } 100 root stack[++top]=NULL; p=root; printf("nInorder Traversal is...n"); 50 60 do p NULL { while(p!=NULL) { 4 stack[++top]=p; 3 p=p->left; 2 } 1 if(top!=0) top0 NULL { finish = 1 p=stack[top]; 50 100 60 top--;
  63. 63. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p=root; printf("nPreorder Traversal is...n"); 50 60 while(p!=NULL) { printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; 1 else 0 p=stack[top--]; top = -1 finish = 0 }}
  64. 64. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p p=root; printf("nPreorder Traversal is...n"); 50 60 while(p!=NULL) { printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; 1 else top0 NULL p=stack[top--]; }}
  65. 65. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p p=root; printf("nPreorder Traversal is...n"); 50 60 while(p!=NULL) { printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; 1 else top0 NULL p=stack[top--]; }}
  66. 66. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p p=root; printf("nPreorder Traversal is...n"); 50 60 while(p!=NULL) { printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; 1 else top0 NULL p=stack[top--]; } 100}
  67. 67. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p p=root; printf("nPreorder Traversal is...n"); 50 60 while(p!=NULL) { printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; 1 else top0 NULL p=stack[top--]; } 100}
  68. 68. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p p=root; printf("nPreorder Traversal is...n"); 50 60 while(p!=NULL) { printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; top1 60 else 0 NULL p=stack[top--]; } 100}
  69. 69. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p p=root; printf("nPreorder Traversal is...n"); 50 60 while(p!=NULL) { printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; top1 60 else 0 NULL p=stack[top--]; } 100}
  70. 70. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p=root; printf("nPreorder Traversal is...n"); p 50 60 while(p!=NULL) { printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; top1 60 else 0 NULL p=stack[top--]; } 100}
  71. 71. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p=root; printf("nPreorder Traversal is...n"); p 50 60while(p!=NULL){ printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; top1 60 else 0 NULL p=stack[top--]; } 100}
  72. 72. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p=root; printf("nPreorder Traversal is...n"); p 50 60while(p!=NULL){ printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; top1 60 else 0 NULL p=stack[top--]; } 100 50}
  73. 73. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p=root; printf("nPreorder Traversal is...n"); p 50 60while(p!=NULL){ printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; top1 60 else 0 NULL p=stack[top--]; } 100 50}
  74. 74. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p=root; printf("nPreorder Traversal is...n"); 50 60 pwhile(p!=NULL){ printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; 1 else top0 NULL p=stack[top--]; } 100 50}
  75. 75. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p=root; printf("nPreorder Traversal is...n"); 50 60 pwhile(p!=NULL){ printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; 1 else top0 NULL p=stack[top--]; } 100 50}
  76. 76. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p=root; printf("nPreorder Traversal is...n"); 50 60 pwhile(p!=NULL){ printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; 1 else top0 NULL p=stack[top--]; } 100 50 60}
  77. 77. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p=root; printf("nPreorder Traversal is...n"); 50 60 pwhile(p!=NULL){ printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; 1 else top0 NULL p=stack[top--]; } 100 50 60}
  78. 78. void pre_order(){ if(root==NULL) { printf("nTree is Empty..."); return; } 100 root stack[++top]=NULL; p=root; printf("nPreorder Traversal is...n"); 50 60while(p!=NULL) p NULL{ printf("%d ",p->data); if(p->right!=NULL) 4 stack[++top]=p->right; 3 if(p->left!=NULL) 2 p=p->left; 1 else 0 p=stack[top--]; top = -1 } 100 50 60}

×