I'm doing an exercise from Chapter 7 of Bjarne Stroustrup's "C++ Programming Language - Third Edition". The exercise is:
-Write a function for entering new words into a tree of tNodes.
-Write a function to write out a tree of tNodes.
-Modify tNode so that it stores only a pointer to an arbitrarily long word stored as an array of characters on free store using new.
-Modify the functions to use the new definition of tNode.
Whereas tNode is:
1 2 3 4 5 6 7
|
struct tNode
{
string word;
int count;
tNode *left;
tNode *right;
};
|
I'm a little confused and I feel I am perhaps going about this in the wrong way. My current interpretation of the exercise is when he says 'tree' I am imagining it in a more literal sense where it branches out to form a tree of objects going from one parent object to perhaps 12 child objects like here:
http://cslibrary.stanford.edu/110/binarytree.gif
However, I am slowly beginning to think that perhaps the intended meaning is actually different and yet deceptively simple. Rather than a tree as show above which branches out, the intended meaning should be viewed more like a string. Imagine the phrase "the brown dog", where 'the' is left of 'brown' and 'dog' is right of 'brown', as if each node were a token in a string.
If anyone has ever read the book and done exercises, I would greatly appreciate some clarification.