Let's suppose we have a RedBlack-Tree implementation which consists of 2 classes:
Tree
- holds the pointer to theNode *root
of the tree and defines all operations over the tree (Insert
,Delete
, etc)Node
- a data storage, which holds pointers toNode *parent
,Node *left
,Node *right
nodes andstd::string key
.
The Tree::Insert()
has the following implementation:
void Tree::Insert(const std::string &key)
{
Node *z = new Node(key);
// adding node logic
}
Now the task: every node has to store the time of its creation.
Limitations: the base tree implementation should be modified as less as possible and should contain details of specific extensions (so it should know nothing about the creation time property).
My thoughts: extending NodeWithTime : Node
and adding unsigned int creation_time
property.
Where I'm in stuck: how would we instantiate the node now?
Any proposals?
PS: it's neither a homework or a job task - I'm just learning c++ and data structures.