Answer:
This task involves implementing a binary search tree with integer-based nodes, extending it by making a subclass of AVL or red-black tree utilizing inheritance, and including a list in the main source file. The next step is to insert 150,000 random numbers into a list, a BST, and a balanced BST (AVL or red-black tree). The same numbers must be inserted into each data structure.
After that, present the user with a simple menu with two options: search for a number in all data structures or exit. If the user selects the first option, ask the user to input a number. Then, search for the number in the list, binary search tree, and balanced binary search tree, recording how long it takes in milliseconds to do each. If the number is found, display the time taken to find it in each structure. If not, let the user know that the number could not be found in any of them and still show the time to complete the search on each structure.
Here is some pseudocode to help you get started:
// Step 1: Implement binary search tree with integer-based nodes
class Node {
int data;
Node* left;
Node* right;
};
class BinarySearchTree {
public:
BinarySearchTree();
~BinarySearchTree();
void insert(int data);
bool search(int data);
private:
Node* root;
};
// Step 2: Extend BST by making a subclass of AVL or red-black tree utilizing inheritance
// Step 3: Include list in the main source file and insert 150,000 random numbers
#include <iostream>
#include <list>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
list<int> numbers;
BinarySearchTree bst;
BalancedBST bbst; // AVL or red-black tree
srand(time(NULL)); // Seed the random number generator
for (int i = 0; i < 150000; i++) {
int r = rand() % 150000 + 1; // Generate a random number between 1 and 150000
numbers.push_back(r);
bst.insert(r);
bbst.insert(r);
}
// Step 4: Present user with a simple menu
while (true) {
cout << "Select an option:" << endl;
cout << "1) Search for a number in all data structures" << endl;
cout << "2) Exit" << endl;
int option;
cin >> option