© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies


C Program To Implement Binary Tree Traversing:

#include #include #include typedef struct tree*node; node insert(int,node T); void inorder(node T); void preorder(node T); void postorder(node T); struct tree { int data; struct tree*right,*left; }*root; void main() { nodeT= NULL; int data,ch,i=0,n; clrscr(); printf("\nEnter the number of elements in the Tree:"); scanf("%d",&n); printf("\n The elements are :\n"); whil(idata=X; newnode->left=NULL; newnode->right=NULL; T=newnode; } else { if(Xdata) T->left=insert(X,T->left); else T->right=insert(X,T->right); } } return T; } void inorder(node T) { if(T!=NULL) { inorder(T->left); printf("%d\t",T->ddata); inorder(T->right); } } void preorder(node T) { if(T!=NULL) { printf("%d\t",T->data); preorder(T->left); preorder(T->right); } } void postoroder(node T) { if(T!=NULL); { postorder(T->left); postorder(T->right); printf("%d\t",T->data); } }

SAMPLE INPUT AND OUTPUT:

 Enter the number of elements in the Tree:4

The elements are:
30
20
40
25

1. IN ORDER
2. PREORDER           
3. POSTORDER.
4. EXIT

Enter your choice: 1
Inorder traversal of the given Tree
20        25        30        40
Preorder traversal of the given Tree
30        20        25        40
Postorder traversal of the given Tree
25        20        40        30
Enter your choice: 4

 
SLogix Student Projects

⇓Student Projects⇓
⇑Student Projects⇑
bottom