|
|
 |
|
|
|
|
74: private:
75: int myAge;
76: };
77:
78:
79: // compare is used to decide where in the list
80: // a particular object belongs.
81: int Cat::Compare(const Cat & theOtherCat)
82: {
83: if (myAge < theOtherCat.myAge)
84: return kIsSmaller;
85: if (myAge > theOtherCat.myAge)
86: return kIsLarger;
87: else
88: return kIsSame;
89: }
90:
91:
92: // ADT representing the node object in the list
93: // Every derived class must override Insert and Show
94: template <class T>
95: class Node
96: {
97: public:
98: Node(){}
99: virtual ~Node(){}
100: virtual Node * Insert(T * theObject)=0;
101: virtual void Show() = 0;
102: private:
103: };
104:
105: template <class T>
106: class InternalNode: public Node<T>
107: {
108: public:
109: InternalNode(T * theObject, Node<T> * next);
110: ~InternalNode(){ delete myNext; delete myObject; }
111: virtual Node<T> * Insert(T * theObject);
112: virtual void Show()
113: {
114: myObject->Show();
115: myNext->Show();
116: } // delegate!
117: private:
118: T * myObject; // the Object itself
119: Node<T> * myNext; // points to next node in the linked list
120: };
121:
122: // All the constructor does is initialize |
|
|
|
 |
|
|
|
|
continues |
|
|
|
|
|