Homework 7 - creating a template container with iterators
Reading: Budd, Chapter 9.
Due Tuesday February 26th, at 10pm.
Program Description - Create a tree template class.
For this assignment you are to create a template version of the tnode class created for assignment
three. Specifically you must create a template class that can be used with the
test program tnodeTemplate.cpp. An examination of the
tnodeTemplate.cpp should reveal that your template class must support the following:
- The template parameter is the type of value stored with each node (in addition to each node
having a string name).
- There must be begin() and end() methods that return an iterator that will iterate over all
nodes in the tree rooted at "this" node, visiting them in prefix depth first order.
- There must be beginChildren() and endChildren() methods that return an iterator that will iterate
over the children of "this" node.
- You must overload operator<< for printing tnodes.
- The same addChild(), getChild(), remove(), parent(), getName(), and getValue() methods as in
the earlier assignment. There is one addition to the specification of these operations.
The addChild() must add the nodes in such a way that the iterators visit the children of a single
node in the order that they were added. Previously there was no specified order.
Both types of iterators must support:
- operator*
- operator==
- operator!=
- operator++
The == operator is not tested in tnodeTemplate.cpp.
Sample Execution
os-prompt% tnodeTest
one:1
two:2
now the whole tree
root:0
one:1
a:11
b:22
two:2
child1:value1
child2:value2
now the whole string tree
sroot:root value
child1:value1
child1-1:value1-1
child2:value2
child2-1:value2-1
child1 subtree should be gone
sroot:root value
child2:value2
child2-1:value2-1
Design/Correctness Points
10 points - with the exception of one line methods, all methods are defined after the class declaration.
10 points - full tree iterator works properly
10 points - child iterator works properly
10 points - basic class template ok
10 points - operator<< properly overloaded
10 points - addChild adds nodes so that the child iterator returns them in the order they were added
15 points - miscellaneous, including correct operation of getChild(), remove(), etc.