void PrintInorder(treeNode *node) { if(node==NULL) { return; } PrintInorder(node->left); printf("%d ",node->data); PrintInorder(node->right); }
int main() { treeNode *root = NULL; root = Insert(root, 5); root = Insert(root, -1); root = Insert(root, 3); root = Insert(root, -14); root = Insert(root, 8); root = Insert(root, 10); root = Insert(root, 9); root = Insert(root, 6); PrintInorder(root); printf("\n"); // root = Delete(root,5); // root = Delete(root,-1); // PrintInorder(root); // printf("\n"); // treeNode * temp; // temp = FindMin(root); // printf("Minimum element is %d\n",temp->data); // temp = FindMax(root); // printf("Maximum element is %d\n",temp->data); // temp = Find(root,8); // if(temp==NULL) // { // printf("Element 8 not found\n"); // } // else // { // printf("Element 8 Found\n"); // } // temp = Find(root,2); // if(temp==NULL) // { // printf("Element 2 not found\n"); // } // else // { // printf("Element 6 Found\n"); // } }
int main() { //treeNode *root = NULL; int x; int ch, num, num1; treeNode * temp; treeNode *med; int m = 1; do { printf("\nSelect a choice from the menu below."); printf("\n1. Generate Binary Search Tree"); printf("\n2. Print the BST in pre-order format"); printf("\n3. Print the BST in in-order format"); printf("\n4. Print the BST in post-order format"); printf("\n5. Print the BST in breadth-first format"); printf("\n6. Find a value in the BST"); printf("\n7. Find the minimum value in the BST nodes"); printf("\n8. Find the maximum value in the BST nodes"); printf("\n9. Calculate the average value of the BST nodes"); printf("\n10. Find the median value of the BST nodes"); printf("\n11. Calculate the sum of the BST nodes"); printf("\n12. Count the number of BST nodes"); printf("\n13. Delete a value in the BST"); printf("\n14. Exit Program"); printf("\n"); printf("\nEnter Choice: "); scanf("%d", &ch); switch (ch) { case 1: genrateTree(); printf("\n"); printf("\nTree in IN-ORDER : "); PrintInorder(root); printf("\n"); break; case 2: PrintPreorder(root); break; case 3: PrintInorder(root); break; case 4: PrintPostorder(root); break; case 5: printLevelOrder(root); break; case 6: printf("\nEnter the element to be Find in TREE: "); scanf("%d", &num); temp=Find(root, num); if (temp->data == num) { printf("Element Found\n"); } else { printf("Element NOT Found\n"); } break; case 7: temp = FindMin(root); printf("Minimum element is %d\n", temp->data); break; case 8: temp = FindMax(root); printf("Maximum element is %d\n", temp->data); break; case 9: in_order_sum(root); printf("Average element is %d\n", sum / counter(root)); sum = 0; break; case 10: med = medianTraverse(root, findHeight(root)); printf("Median Value is %d\n", med->data); break; case 11: in_order_sum(root); printf("\nThe sum of all the elements are:%d\n", sum); sum = 0; break; case 12: printf("Total Number of Nodes %d\n", counter(root)); break; case 13: PrintInorder(root); printf("\n"); printf("\nEnter the element to be Deleted: "); scanf("%d", &num); Delete(root, num); break; case 14: exit(0); break; default: exit(0); } //printf("%d", rootNode->data); printf("\n"); printf("\nIf you want to return to the menu, press 1."); printf("\nChoice: "); scanf("%d", &num); } while (num == 1); }