|
|
 |
|
|
|
|
26: // Data class to put into the linked list
27: // Any class in this linked list must support two methods:
28: // Show (displays the value) and Compare (returns relative position)
29: class Data
30: {
31: public:
32: Data(int val):myValue(val){}
33: ~Data(){}
34: int Compare(const Data &);
35: void Show() const { cout << myValue << endl; }
36: private:
37: int myValue;
38: };
39:
40: // Compare is used to decide where in the list
41: // a particular object belongs.
42: int Data::Compare(const Data & theOtherData)
43: {
44: if (myValue < theOtherData.myValue)
45: return kIsSmaller;
46: if (myValue > theOtherData.myValue)
47: return kIsLarger;
48: else
49: return kIsSame;
50: }
51:
52: // forward declarations
53: class Node;
54: class HeadNode;
55: class TailNode;
56: class InternalNode;
57:
58: // ADT representing the node object in the list
59: // Every derived class must override Insert and Show
60: class Node
61: {
62: public:
63: Node(){}
64: virtual ~Node(){}
65: virtual Node * Insert(Data * theData)=0;
66: virtual void Show() const = 0;
67: private:
68: };
69:
70: // This is the node which holds the actual object
71: // In this case the object is of type Data
72: // We'll see how to make this more general when
73: // we cover templates
74: class InternalNode: public Node |
|
|
|
 |
|
|
|
|
continues |
|
|
|
|
|