CMSC 341 Fall 1998 Project 3 This is my solution for project 3 -- the concordance.

Some notes about the implementation....

The main program only interfaces to the concordance class. The concordance class hides the fact that the data is kept in a tree. The concordance class member functions call concordance tree member functions... that's all.

This way if we ever decide on a different implementation (linked-list, array, whatever) the usersof the concordance class (like our main program) don't change. Only the member functions inside the concordance class change.

Notice too that the main program only deals with 'C' strings (char *). It has no "knowledge" of the concordance data class.

The CTree class is NOT a template...it a BST that contains a specific kind of data (CData). The CData class becomes the 'Element' field in the Tree_Nodes. Because the BST is the CTree's base class, the BST's constructor and destructor will automatically be called whenver the CTree constructor or destructor are called. The CTree class uses some BST functions (Print_Tree, Find) and adds functions which are specific to the CTree (PrintSomeNodes) and overrides the Insert function.
CTree is made a friend of Tree_Node (as is BST) to allow it to reference the Left and Right pointers. Notice that CTree only deals with CData objects. It does not have "knowledge" that the words in the CData are really String objects.

Notice how each class does not attempt to "look" inside the classes it deals with and how the operators work their way down the classes. For example....

The CTree "Insert" code compares two CData obects (often the parameter X and T->Element). The code doesn't know "how" to compare them. That's up to the CData class. Only the CData class "knows" what it means for one CData object to be "less than" or "greater than" or "equal to" another -- that's up to the CData object's operator< (or operator> or operator==) to know. The CData object's operators compare their text elements, but don't know how to compare String objects -- that's up to the String's operator<, etc. The String object's comparison operators.... they eventually call the string routines (strcmp).

The code....