Question: c + + , please solve the to do sections in the BSTMap. #ifndef _ _ BSTMAP _ H _ _ #define _ _ BSTMAP
c please solve the to do sections in the BSTMap.
#ifndef BSTMAPH
#define BSTMAPH
#include
#include
#include
#include
#include
#include
#include
using namespace std;
class BSTMapNode
public:
string key;
int value;
BSTMapNode left;
BSTMapNode right;
BSTMapNodeconst string &k const int &v
BSTMapNode l nullptr,
BSTMapNode r nullptr
key k;
value v;
left l;
right r;
;
class BSTMap
friend class BSTPrinter;
private:
BSTMapNode root; Root of the BST
public:
BSTMap root nullptr;
~BSTMap clearroot;
Delete all nodes.
void clearBSTMapNode root
if root nullptr
return;
clearrootleft;
clearrootright;
delete root;
Print the BST level by level, from top to bottom and left to right.
void printostream &os
vector lines;
vector level;
vector next;
level.pushbackroot;
int nn ;
sizet widest ;
while nn
vector line;
nn ;
for BSTMapNode n : level
if n nullptr
line.pushback;
next.pushbacknullptr;
next.pushbacknullptr;
else
std::stringstream ss;
ss nkey : nvalue;
string aa ssstr;
line.pushbackaa;
if aalength widest
widest aalength;
next.pushbacknleft;
next.pushbacknright;
if nleft nullptr
nn;
if nright nullptr
nn;
if widest
widest;
lines.pushbackline;
vector tmp level;
level next;
next tmp;
next.clear;
int perpiece lines.atlinessizesizewidest ;
for sizet i ; i lines.size; i
vector line lines.ati;
int hpw intfloorperpiece f;
if i
for sizet j ; j line.size; j
split node
char c ;
if j
if lineatj
c ;
else if j line.size && line.atj
c ;
os c;
lines and spaces
if lineatj
for int k ; k perpiece ; k
os ;
else
for int k ; k hpw; k
os j : ;
os j : ;
for int k ; k hpw; k
os j : ;
os
;
os
;
for sizet j ; j line.size; j
string f line.atj;
int gapintceilperpiece f flengthf;
int gapintfloorperpiece f flengthf;
for int k ; k gap; k
os ;
os f;
for int k ; k gap; k
os ;
os
;
os
;
perpiece ;
void putconst string &ik const int &val;
bool findconst string &sk const;
int getconst string &sk const;
void removeconst string &rk;
;
Insert the keyvalue pair ik and val to the BSTMap.
@param ik The key to insert
@param val The value corresponding to the key
void BSTMap::putconst string &ik const int &val
TODO
Search for given key in the BSTMap.
@param sk The search key
@return true if sk is in the BSTMap
bool BSTMap::findconst string &sk const
TODO:
bool v false; placeholder to make sure the code can compile
return v;
Return the value of the given search key sk in the BSTMap.
int BSTMap::getconst string &sk const
TODO: You may assume that sk is in the BSTMap.
int v; placeholder to make sure the code can compile
return v;
Remove rk and its corresponding value from the BST
void BSTMap::removeconst string &rk
TODO: You may assume that rk is in the BSTMap.
#endif BSTMAPH
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
