Question: For this problem, we will implement a Complete tree using nodes. For example, in C++ the node and class definitions would look like this: struct

 For this problem, we will implement a Complete tree using nodes.

For example, in C++ the node and class definitions would look like

this: struct Node int data; Node left; Node* right; Node parent; class

For this problem, we will implement a Complete tree using nodes. For example, in C++ the node and class definitions would look like this: struct Node int data; Node left; Node* right; Node parent; class CompleteTree C Node* root; You will need to implement the following operations on complete trees: fromArray which creates nodes for a complete tree represented by the given array toArray which returns the array representation of the complete tree isBST which returns true if the complete tree is a Binary Search Tree preOr postOrder which prints a post-order traversal of the tree numNodesInLookup which prints the number of nodes visited when looking up the given der which prints a pre-order traversal of the tree value. For example, in C++,the function headers would be the following class CompleteTree Node* root; public CompleteTree) void fromArray (vector list) vector int> toArray bool isBSTO void pre0rder O void postorder int numNodesInLookup(int value) J; Input 100, denoting the number of nodes in the The next line will consist of n integers that make up the values to be stored in the 10, denoting the number of commands "pre- The first line contains an integer n,0 S tree tree . The third line contains an integerm,0Sm in the following lines. The next m lines have one of the following commands "toArray", "isBST Order", "post Order", "numNodesInLookup") per line. Constraints In this proble, a binary search tree must have unique values. You can assume the value given to "numNodesInLookup" is in the tree. numNodesInLookup should try to look at as few nodes as possible. This means that if the tree is a Binary Search Tree, it should use binary search. If the tree is not a binary tree, use level-order traversal Output "toArray" will print out the array representation of the complete tree "isBST" wil print out either "or false" ."preOrder and "postOrder" will print out the order they visit each node respectively numNodesInLookup" will print out an integer Sample Input 1 10 1 2 3 456789 10 4 isBST pre0rder toArray numNodesInLookup 4 Sample Output 1 false 1 2 4 89510 3 67 1 2 3 4 5 6 7 89 10 4 Sample Input 2 12 100 53 172 24 64 150 200 12 33 60 98 130 isBST postorder numNodesInLookup 98 Sample Output 2 true 12 33 24 60 98 64 53 130 150 200 172 100

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!