#pragma once
#include "tree.h"
// tree represents a binary search tree of key-value pairs
// keys and values are both strings)
class bstree: public tree {
public:
bstree(); // constructor for empty tree
~bstree(); // destructor (delete all tree nodes)
string lookup(string k); // searches tree for the specified key k,
// returns the associated string, returns "NOT FOUND"
// if no such key is found
void insert(string k, string v); // if a node with key k already exists then insert
// replaces its associated value with v,
// otherwise inserts a new node with the given key/value
bstree(const bstree& orig); // copy constructor
bstree(bstree&& orig); // move constructor
bstree& operator=(const bstree& rhs); // overload the assignment operator (makes deep copy)
private:
tnode* lookup(string k, tnode* t); // searches subtree t for a node whose key matches k
// and returns a pointer to the node (if found)
// or nullptr (if no such node is found)
void insert(string k, string v, tnode* &t); // performs insert within subtree t
void copy(tnode* &t, tnode* origt); // make t a deep copy of subtree origt
};
|