Tree Traversal
Tree Traversal
post-order.
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
struct tnode
{
int data;
struct tnode *left, *right;
};
int main()
{
int data, ch;
clrscr();
while (1)
{
printf("\n1. Insertion\n2. Pre-order\n");
printf("3. Post-order\n4. In-order\n");
printf("5. Exit\nEnter your choice:");
scanf("%d", &ch);
switch (ch)
{
case 1:
printf("Enter your data:");
scanf("%d", &data);
insertion(&root, data);
break;
case 2:
preorder(root);
break;
case 3:
postOrder(root);
break;
case 4:
inOrder(root);
break;
case 5:
exit(0);
default:
printf("You've entered wrong option\n");
break;
}
}
getch();
return 0;
}
Output: