Question
WRITE IN C++ Enter integers through the keyboard. While entering the numbers, create a binary search tree. For a NULL node enter -1. For the
WRITE IN C++
Enter integers through the keyboard. While entering the numbers, create a binary search tree. For a NULL node enter -1. For the created binary tree write its preorder, inorder, postorder and level order traversals. Then, ask the user to insert a value of a node in the tree. Write a function to find the predecessor of the given node (its value and address). If the node is not found, the function should return NULL. If the found node is the root, the function should return NULL, as well. If the first value that is entered is equal to -1, then don't print the tree, its traversals or the predecessor of the given node, but instead only print a message that the tree is empty. Example output:
Enter the walue for the root (1 for empty tree): 5 Enter the next element to enter in the binary search tree (1 for end): 2 Enter the next element to enter in the binary search tree (1 for end =1 Enter the next element to enter in the binary search tree (1 for end =3 Enter the next element to enter in the binary search tree (1 for end )8 Enter the next element to enter in the binary search tree (1 for end =6 Enter the next element to enter in the binary search tree (1 for end =7 Enter the next element to enter in the binary search tree (1 for end )9 Enter the next element to enter in the binary search tree (1 for end =1 5(0782950) 12 (0)782968) 11 (0) 1782980) INULI INULL 13(0782998) INULL I INULL 18(07829b0) 16(0782co) I INULL I I7 (0x7829e0) INULL I I INULL i iNULL I INULL Enter the element whose predecessor has to be found: 3 The predecessor of the element 3 is the element 2 located on address 0782968 Process returned 0 (0x) execution time =15.644s Press any key to continueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started