Suppose you are given the following public parts of a C++
class declaration for a binary tree that stores keys in
alphabetical order:
template<class Key, class Value>
class BinaryTree {
public:
void insert(Key key, Value val);
// returns true if the key is in the tree and false otherwise.
// Positions the cursor to point to the tree node that contains the
// key if such a node exists and otherwise to the first tree node
// with a value greater than key
boolean find(Key key);
// returns the value of the tree node pointed to by the cursor
Value get();
void delete(Key key);
}
- Write a line of code that declares a variable, x,
to be a BinaryTree
with an integer key and a string (char *) value.
The variable should be
a value object (i.e., stack allocated).
- Write a line of code that declares a variable, y,
to be a BinaryTree
with a string (char *)
key and a Payroll pointer value (assume Payroll is
a class). The variable should be a pointer.
- Write a line of code that allocates a BinaryTree object off the
heap and assigns it to y.
- Write a function that takes as inputs an integer key and a
reference to a BinaryTree object that
has an integer key and a standard template library
string value (i.e., the
value should be a string object from C++'s standard template
library). The function
should look up the integer key in the BinaryTree object and
return the associated string if the integer key is found, and
0 otherwise.
- Write a line of code that calls your function and assigns the
result to a standard template library string variable.