Write a C++ class called BSTArray with five basic functions for the BST: insert, search, findmin, findmax, and print: 1. int search(x): Find and return the index that stores element x using binary search tree mechanism. Print out all the elements in the search path. You must use the binary tree search algorithm. In other words, do NOT just do a linear search of the array. If the x value is not found, report an error and return -1. 2. int findmax( ): Find and return maximum value in BST. You must use the binary tree search algorithm. In other words, do NOT just perform a linear search of the array. If the tree is empty, return -1. 3. int findmin( ): Find and return minimum value in BST. In other words, do NOT just perform a linear search of the array. If the tree is empty, return -1. 4. void print( ): Print out the BST structure in the form of an array with index. Specifically, print the index of the array and the value stored at that index starting at zero and ending at the capacity of the array. This is not inorder, preorder, or postorder traversal. In this case, DO use linear array traversal. You may skip printing “empty” array values. 5. void insert(x): Insert a value element x into BST. Report an error if the value already exists in the tree. After you finished all functions, implement a driver that makes the following method calls: insert(5) insert (8) insert (3) insert (1) insert (4) insert (9) insert (18) insert (20) insert (19) insert (2) Perform print ( ) Perform findmax ( ) and print the return value in your driver Perform findmin( ) and print the return value in your driver Perform search(3) in the BST and print the index that is returned in your driver Perform search(18) in the BST and print the index that is returned in your driver Perform search(19) in the BST and print the index that is returned in your drive

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question

Write a C++ class called BSTArray with five basic functions for the BST: insert, search,
findmin, findmax, and print:

1. int search(x): Find and return the index that stores element x using
binary search tree mechanism. Print out all the elements in the search path.
You must use the binary tree search algorithm. In other words, do NOT just
do a linear search of the array. If the x value is not found, report an error
and return -1.
2. int findmax( ): Find and return maximum value in BST. You must use
the binary tree search algorithm. In other words, do NOT just perform a
linear search of the array. If the tree is empty, return -1.
3. int findmin( ): Find and return minimum value in BST. In other words,
do NOT just perform a linear search of the array. If the tree is empty,
return -1.
4. void print( ): Print out the BST structure in the form of an array with
index. Specifically, print the index of the array and the value stored at that
index starting at zero and ending at the capacity of the array. This is not
inorder, preorder, or postorder traversal. In this case, DO use linear array
traversal. You may skip printing “empty” array values.
5. void insert(x): Insert a value element x into BST. Report an error if the
value already exists in the tree.

After you finished all functions, implement a driver that makes the following method
calls:

insert(5)
insert (8)
insert (3)
insert (1)
insert (4)
insert (9)
insert (18) insert (20)
insert (19)
insert (2)
Perform print ( )
Perform findmax ( ) and print the return value in your driver
Perform findmin( ) and print the return value in your driver
Perform search(3) in the BST and print the index that is returned in your driver
Perform search(18) in the BST and print the index that is returned in your driver
Perform search(19) in the BST and print the index that is returned in your driver

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 7 images

Blurred answer
Knowledge Booster
Linked List Representation
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT