Page 233 - DCAP407_DATA_STRUCTURE
P. 233

Data Structure



                                                              break;
                                        /*Switches to preorder function and performs preorder traversal*/
                                                case 2 :preorder(root);
                                                       break;

                                        /*Switches to postorder function and performs postorder traversal*/
                                                case 3 :postorder(root);
                                                       break;
                                                case 4 :exit(0);                    //Exits from the function
                                                default:printf("Error ! Invalid Choice ");   //Prints invalid statement
                                                       break;
                                                }
                                 }

                                 getch();
                                 }
                          }
                          Output:
                          Enter the root : 5
                          Enter another number: 7

                          Right branch of 5 is 7
                          1. Inorder traversal
                          2. Preorder traversal
                          3. Postorder traversal
                          4. Exit
                          Enter choice: 1
                              5         7

                          1. Inorder traversal
                          2. Preorder traversal
                          3. Postorder traversal
                          4. Exit
                          Enter choice: 2
                                 5      7

                          1. Inorder traversal
                          2. Preorder traversal
                          3. Postorder traversal
                          4. Exit
                          Enter choice: 3
                               7      5





                          226                     LOVELY PROFESSIONAL UNIVERSITY
   228   229   230   231   232   233   234   235   236   237   238