14 - WAP To Implement Binary Tree Traversal (Inorder, Preoder and Postorder)
The document contains code to implement traversal of a binary tree in C including preorder, inorder, and postorder traversal. It defines a node structure with left, right, and data pointers. Functions are included to insert nodes, traverse the tree preorder, inorder, and postorder, and a menu driver is provided to test the different traversal methods.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
48 views
14 - WAP To Implement Binary Tree Traversal (Inorder, Preoder and Postorder)
The document contains code to implement traversal of a binary tree in C including preorder, inorder, and postorder traversal. It defines a node structure with left, right, and data pointers. Functions are included to insert nodes, traverse the tree preorder, inorder, and postorder, and a menu driver is provided to test the different traversal methods.
{ printf("\n\n\t MENU "); printf("\n\n Enter 1: Insert a node in the BT "); printf("\n\n Enter 2: Display ( preorder ) the BT "); printf("\n\n Enter 3: Display ( inorder ) the BT"); printf("\n\n Enter 4: Display ( postorder ) the BT"); printf("\n\n Enter 5: END"); printf("\n\n Enter your choice : "); scanf("%d" , &choice );
switch(choice ) {
case 1 : printf(" \n\n Enter integer : To quit enter 0 \n\n\t "); scanf("%ld",&digit); while(digit!=0) { tree=insert(tree,digit); scanf("%ld",&digit); } continue;
case 2 : printf("\n Preorder traversing TREE :\n\n"); preorder(tree); continue;
case 3 : printf("\n Inorder traversing TREE :\n\n"); inorder(tree); continue;
case 4 : printf("\n Postorder traversing TREE :\n\n"); postorder(tree); continue;
case 5 : printf("\n\n END"); getch(); exit(0); break ; } } while(choice!=5); } // End of main( )