Question: Plzzzzz only one function need to be complete note: The uses g++ to compile C++. source code part (1) part (2) Note the finction plz

Plzzzzz only one function need to be complete note: The uses g++ to compile C++. Plzzzzz only one function need to be complete note: The uses g++

source code

to compile C++. source code part (1) part (2) Note the finction

plz Just do part 2 the complexities We expect you to complete

the following function: calcSum: calculate the sum total of all keys in

the subtree rooted at Nodes, and saves the result to s.sum using

part (1)

namespace std; 1/ Utility functions void loadFile(string frame, fstream& file) file.open(fname.c_str()); if

(file.fail()) cout key ":" cout left); cout right); cout sunprintTree(s->right, space); cout

part (2)

key sum printTree(s->left, space); BS Map::Node** BSTMap::find(int k) const { Node* w

Note

= root; Node* z = NULL; while (w && (w->key != k))

the finction plz
Just do part 2 the complexities

We expect you to complete the following function: calcSum: calculate the sum total of all keys in the subtree rooted at Nodes, and saves the result to s.sum using namespace std; 1/ Utility functions void loadFile(string frame, fstream& file) file.open(fname.c_str()); if (file.fail()) cout key ":" cout left); cout right); cout sunprintTree(s->right, space); cout key sum printTree(s->left, space); BS Map::Node** BSTMap::find(int k) const { Node* w = root; Node* z = NULL; while (w && (w->key != k)) { Z = W; w = (w->key > k) ? W->left : w->rig Node** wAndZ = new Node * [2]; wAndZ[0] = w; wAndZ[1] = z; return wAndz; its only node) BSTMap: : Nodes BSTMap::put(int k) { Node** wAndz = find(k); Node* W = wAndZ[0]; Node* z = wAndZ[1]; delete wAndz; if (w) { return w; Node* x = new Node(k, 0, NULL, NULL, 2); if (z) { if (z->key > k) z->left = x; else z->right = x; else root = x; n++; if (n == 1) root = x; return x; void BSTMap::calcSum(Node* s) { Your code here 1/ OUTPUT: size of the tree int BSTMap::size() const { return n; 77 OUTPUT: true if the tree is empty; false otherwise bool BSTMap::empty() const { return (!root); int main() { string inputFilename = "input.txt"; string line; BSTMap B; 1/ open input file fstream inputFile; loadFile(inputFilename, inputFile); while (getline(inputFile, line)) { Il trim whitespace each input cout tokens; while (getline(liness, token,' ')) 1/ trim whitespace token.erase(token.find_last_not_of(" \t") + 1); tokens.push_back(token); if (tokens.size() > 0) command - tokens[@]; // first token is the command else command = ""; Input File Format Each line in the input file can represent a single or multiple commands depending on the context. put Inserts a node into the BST for each key provided, but only if a node with that key doesn't already exist. sum Calculates the sum of all keys in every subtree in the BST, starting from the root print Display the current BST using a preorder/infix parenthetic representation: [, ] (), () printTree Display the current BST using a representation which reflects the structure of the tree: rightchild key: sum root key: sum left.child key: sum Sample Input File input.txt and Sample Output The following input file: put 12 6 20 2 9 15 22 sum printTree should produce the following output: put 12 6 20 2 9 15 22 sum printTree 22:22 20:57 15:15 12:86 9:9 6:17 2:2 Write your answer for each method using big-Oh notation as a function of the number nodes n in the binary search tree at the time of the call to that method. Running Time Space Method print print Tree find put calcSum size empty Write down the preconditions and postconditions of the following methods. (Hint: Look at the examples of pre/post conditions in the source code file provided for the respective language that you used.) 1. Method: calcSum Preconditions: Postconditions: C++ only: C++ is not a cross platform language, so it is possible that code which compiles in one machine does not compile on another. The autograder uses g++ to compile C++. It is ultimately your responsibility to ensure that the autograder can compile your code

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!