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++.
source code




part (1)


part (2)

Note

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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
