Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey everyone, if anyone could help me real quick with this question that'd be great! thanks :) C++ EVERYONE!!! Below is the Cpp, file to

Hey everyone, if anyone could help me real quick with this question that'd be great! thanks :) C++ EVERYONE!!!

Below is the Cpp, file to copy, (Paste formatted into your respetive ide's (I will repost if i have to, to get all parts answered

image text in transcribed

image text in transcribed

#include  #include  #include  #include  #include  using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree // change to stored attribute if efficiency is important template  int size(N* root) { if (root == 0) return 0; return 1 + size(root->left) + size(root->right); } // returns depth of tree // change to stored attribute if efficiency is important template  int depth(N* root) { if (root == 0) return 0; return 1 + max(depth(root->left), depth(root->right)); } // returns true if tree is valid // also checks size for randomised trees and depth for avl trees template  bool valid(N* root) { if (root == 0) return true; return valid(root->left) && valid(root->right) && (root->left == 0 || root->left->key == root->key || root->left->key key) && (root->right == 0 || root->key == root->right->key || root->key right->key) && (mode != randomised || size(root) == 1 + size(root->left) + size(root->right)) && (mode != avl || depth(root) == 1 + max(depth(root->left), depth(root->right))) ; } // displays tree as a single-line with parens to indicate structure // only really useful for small trees template  void print(N* root, ostream& out, bool verbose) { if (root != 0) { out left, out, verbose); out key; if (verbose) { out value; if (mode == randomised) out right, out, verbose); out  void explode (N* root, ostream& out, bool verbose, string leader = "", string before = " ", string after = " ") { if (root != 0) { explode(root->right, out, verbose, leader + before + " ", " ", "|"); out key; if (verbose) { out value; if (mode == randomised) out left, out, verbose, leader + after + " ", "|", " "); } } /* * Binary Search Tree template * Key is key type (must define " class BST { struct Node { Key key; Value value; Node* left; Node* right; }; public: BST() { root = 0; } // retuns true (and modifies value) if given key found bool search(const Key& key, Value& value) { // add code here return false; } // inserts given key and value void insert(const Key& key, const Value& value) { // add code here } // removes first-found match (if any) to given key void remove(const Key& key) { // add code here } // ------- tree information (for debugging) bool valid() { return ::valid(root); } int size() { return ::size(root); } int depth() { return ::depth(root); } void print(ostream& out, bool verbose) { ::print(root, out, verbose); cout  tree; string command; while (getline(cin, command)) { char function = 'i'; int limit = 100; char sequence = '='; int count = 1; stringstream tokens(command); if (tokens) tokens >> function; if (tokens) tokens >> limit; if (tokens) tokens >> sequence; if (tokens) tokens >> count; int found = 0; int total = 0; for (int i = 0; i   Task The program searching .cpp contains an incomplete class definition for a binary search tree, defined according to the following template. template > When you're ready to submit your wor use handin searching  Background The main program interprets a simple command language (read from standard input) for inserting removing, and searching the tree. Each command takes the following form function limit sequence count The function field can be insert), r (remove), f (find), or t (total). The find and tota functions report the number of nodes found or the total of the values found on standard output. Th sequence field can be (random), (ascending), (descending), or (fixed). For example i 100 1000 insert 1000 keys K 100 in ascending sequence r 100 100 remove 100 random keys 100 f 100 100000 search for 100000 keys 100 i 123 insert key 123 seq defaults to and count to 1) t 100 10000 total values of 1000 searches with rand keys 100 Several commands are available to help debug your code print current tree (display compact form) explode current tree (display multi-line form) report depth of tree report size of tree

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions