Question: ANSWER ONLY WHERE IT SAYS / / YOUR CODE HERE. USE C + + ONLY PLEASE! #include #include #include #include #include #include #include #include #include
ANSWER ONLY WHERE IT SAYS YOUR CODE HERE. USE C ONLY PLEASE!
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
void loadFilestring fname, fstream& file
file.openfnamecstr;
if filefail
cout "Cannot open file fname endl;
# Purpose: Class definition of a simple implementation of an ordered map ADT,
# mapping integers keys to integer values, using a binary search tree BST with a
linkedstructure representation
# NOTE: only basic methods of the ordered map ADT ie put, erase, find, size,
empty and some auxiliary functions eg successor and predecessor implemented
# NOTE: For the sake of consistency with the implementation on other programming
languages eg Java and C this simple implementation does not use overloading
of the or del operator in Python. Also, the documentationcommentsdescription
of methods uses the term "NULL" instead of "None" as actually used in Python
implementations
class BSTMap
public:
simple data structure used to create nodes for linkedlist BSTbased
implementation of an ordered map ADT
from integer keys to integer values
class Node
public:
int key;
int value;
Node left;
Node right;
Node parent;
node constructors
Node : leftNULL rightNULL parentNULL;
Nodeint k int v :
keyk valuev leftNULL rightNULL parentNULL;
Nodeint k int v Node l Node r Node p : keyk valuev leftl
rightr parentp;
node desctructor
virtual ~Node;
overloading output stream for a representation of BST node w
friend ostream& operatorostream& os const Node& w
os wkey : wvalue ;
return os;
;
overloadable print node stats
virtual void printStats cout this; ;
;
prints a representation of BST node w
overloadable
INPUT: node w
virtual void printNodeconst Node w const if w cout Node w; ;
tree constructor
BSTMap : rootNULL n;
tree destructor
virtual ~BSTMap;
basic map operations
Node findint k const;
void putint k int v;
void eraseint k;
int size const;
bool empty const;
auxiliary utilities
Node youngestAncestorTypeNode w bool checkleft const;
Node youngestDescendantTypeNode w bool checkleft const;
Node successorNode w const;
Node predecessorNode w const;
print utilities
void print const; print as parenthetic string
void printTreeNode s int space const;
void printMap const;
void printTreeMapNode s int space const;
protected:
data member: tree root node
Node root;
overloadable auxiliary node creation utility
virtual Node createNodeint k int v Node l Node r Node p return new
Nodekvlrp; ;
auxiliary print utilities
void printAuxconst Node w bool simple const; print utility
void printTreeAuxNode s int space, bool simple const;
auxiliary utilities
void makeChildNode p Node c bool isLeft;
Node findNodeint k const;
virtual Node putNodeint k int v;
virtual Node eraseNodeint k;
private:
auxiliary utilities
virtual void deleteNodeNode w;
virtual void deleteAll;
Node removeNodeNode w;
data member: tree size number of nodesmap entries
int n;
;
Purpose: Implement member functionsmethods of BSTMap class
# utilityaux function to print out a parenthetic string representation of the
BST
# INPUT: a node w in the BST or subclass whose subtree is to be
# printed out; a boolean flag, simple, determining whether a
# simple key:value pair of the BST node or if overloaded a
# possibly more sophisticated representation based on
# characteristics of a subclass object
void
BSTMap::printAuxconst BSTMap::Node w bool simple const
if w
if simple
cout w ;
else
cout ;
printNodew;
cout ;
cout ;
printAuxwleft, simple;
cout ;
printAuxwright, simple;
cout ;
print out a parenthetic string representation of the whole BST
void
BSTMap::print const
printAuxroot false;
cout endl;
print out a parenthetic string representation of the whole BST
using simply the keyvalue info of the map entries in each node
void
BSTMap::printMap const
printAuxroot true;
cout endl;
# utilityaux method to print out a treelike layout of the whole
# BST using a reverse inorder traversal INPUT: a node s in the BST
# whose rooted subtree needs to be printed; a natural number,
# space, for the minimum space separation required between the
# root and left side of the terminal and between each node and its
# children; a boolean flag, simple, determining whether a simple
# key:value pair of We expect you to com
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
