void displayInOrder(node *n) { if(n != NULL) { displayInOrder(n->leftChildNode); printf("%d ", n->data); displayInOrder(n->rightChildNode); } }
void BST<T1, T2>::displayInOrder(BST<T1, T2> *node) { if (node != NULL) { displayInOrder(node->mLeft); cout << node->mData << " "; displayInOrder(node->mRight); } }
void BinaryTree<T>::displayInOrder(TreeNode *nodePtr) const { if (nodePtr) { displayInOrder(nodePtr->left); cout << nodePtr->value << "\n"; displayInOrder(nodePtr->right); } }
void AvlTree::displayInOrder(AvlNode *v) { if (v != NULL) { displayInOrder(v->left); std::cout << v->key << " "; outputFile << v->key << " "; displayInOrder(v->right); } }
void displayInOrder(Node *p){ if(p == NULL){ return; } else{ displayInOrder(p->left); printf("%d\t", p->data); displayInOrder(p->right); } }
int main(void) { int ch, num, num1; do { printf("\nSelect a choice from the menu below."); printf("\n1. Insert a node."); printf("\n2. Search for a node."); printf("\n3. Delete a node."); printf("\n4. Display the Binary Search Tree."); printf("\nChoice: "); scanf("%d", &ch); switch(ch) { case 1: printf("\nEnter an element: "); scanf("%d", &num); //printf("YESYES"); insertNode(num, &rootNode); break; case 2: printf("\nEnter the element to be searched for: "); scanf("%d", &num); searchNode(num, rootNode); break; case 3: printf("\nEnter the element to be deleted: "); scanf("%d", &num); deleteNode(num, rootNode); break; case 4: printf("\nSelect an order for the elements to be display in."); printf("\n1. Pre-order."); printf("\n2. Post-order."); printf("\n3. In-order."); printf("\nChoice: "); scanf("%d", &num1); switch(num1) { case 1: printf("\nPre-order Display: "); displayPreOrder(rootNode); break; case 2: printf("\nPost-order Display: "); displayPostOrder(rootNode); break; case 3: printf("\nIn-order Display: "); displayInOrder(rootNode); break; default: exit(0); } break; default: exit(0); } printf("\nIf you want to return to the menu, press 1."); printf("\nChoice: "); scanf("%d", &num); } while(num == 1); return 0; }
void BST<T1, T2>::showInOrder() { displayInOrder(mRootNode); }
int main(void) { Node *root = NULL; int choice, ele; setbuf(stdout, NULL); printf("Enter choice : 1 for add Binary Search Tree Iteratively\n2 for add Binary Search Tree Recursively\n3 for display in Pre Order\n4 for display in In Order\n5 for display in Post Order\n6 to count no of BST Nodes\n7 to count Height of BST\n8 to check if it is Strict BST\n9 to check if it is Complete BST\n10 for Binary Search Recursively\n11 for Binary Search Recursively\n12 to add to Binary Tree Iteratively\n13 to add to Binary Tree Recursively\n14 to find Largest element in BT\n15 to count number of nodes in BT\n"); do{ printf("Enter choice : "); scanf("%d", &choice); switch (choice) { case 1: // Add BST Iterative printf("Enter a value\n"); scanf("%d", &ele); addBinarySearchTree(&root, ele); break; case 2: // Add BST Recursively printf("Enter a value\n"); scanf("%d", &ele); addBinarySearchTreeRecursively(&root, ele); break; case 3: // Display Pre Order displayPreOrder(root); printf("\n"); break; case 4: // Display In Order displayInOrder(root); printf("\n"); break; case 5: // Display Post Order displayPostOrder(root); printf("\n"); break; case 6: // Count Binary Search Tree Node ele = countBinarySearchTreeNodes(root); printf("%d\n",ele); break; case 7: // Height Binary Search Tree Node ele = heightBinarySearchTree(root); printf("%d\n", ele); break; case 8: // Check if Strict Binary Search Tree if(isStrictBinarySearchTree(root) == 1){ printf("Is Strict Binary Search Tree\n"); } else{ printf("Not a Strict Binary Search Tree\n"); } break; case 9: // Check if Complete Binary Search Tree if(isCompleteBinarySearchTree(root) >= 1){ printf("Is Strict Binary Search Tree\n"); } else{ printf("Not a Strict Binary Search Tree\n"); } break; case 10: // Binary Search Tree Iteratively printf("Enter a value to search\n"); scanf("%d", &ele); if(binarySearchIterative(root, ele) == 1){ printf("Exists\n"); } else{ printf("Does not exist\n"); } break; case 11: // Binary Search Tree Recursively printf("Enter a value to search\n"); scanf("%d", &ele); if(binarySearchRecursion(root, ele) == 1){ printf("Exists\n"); } else{ printf("Does not exist\n"); } break; case 12: // Add Binary Tree Iteratively printf("Enter a value\n"); scanf("%d", &ele); addBinaryTreeIteratively(&root, ele); break; case 13: // Add Binary Tree Recursively printf("Enter a value\n"); scanf("%d", &ele); addBinaryTreeRecursively(&root, ele); break; case 14: // Largest Binary Tree ele = largestBinaryTree(root); printf("Largest element is : %d",ele); break; case 15: // Count No of Binary Tree Nodes ele = countBinaryTreeNodes(root); printf("%d\n", ele); break; default:{ choice = -1; } } }while(choice != -1); return EXIT_SUCCESS; }
void displayInOrder() { displayInOrder(root); }