|
|
 |
|
|
|
|
75: {
76: public:
77: InternalNode(Data * theData, Node * next);
78: virtual ~InternalNode(){ delete myNext; delete myData; }
79: virtual Node * Insert(Data * theData);
80: virtual void Show() const { myData->Show(); myNext->Show(); } // delegate!
81:
82: private:
83: Data * myData; // the data itself
84: Node * myNext; // points to next node in the linked list
85: };
86:
87: // All the constructor does is to initialize
88: InternalNode::InternalNode(Data * theData, Node * next):
89: myData(theData), myNext(next)
90: {
91: }
92:
93: // the meat of the list
94: // When you put a new object into the list
95: // it is passed ot the node which figures out
96: // where it goes and inserts it into the list
97: Node * InternalNode::Insert(Data * theData)
98: {
99:
100: // is the new guy bigger or smaller than me?
101: int result = myData->Compare(*theData);
102:
103:
104: switch(result)
105: {
106: // by convention if it is the same as me it comes first
107: case kIsSame: // fall through
108: case kIsLarger: // new data comes before me
109: {
110: InternalNode * dataNode = new InternalNode(theData, this);
111: return dataNode;
112: }
113:
114: // it is bigger than I am so pass it on to the next
115: // node and let HIM handle it.
116: case kIsSmaller:
117: myNext = myNext->Insert(theData);
118: return this;
119: }
120: return this; // appease MSC
121: } |
|
|
|
 |
|
|
|
|
continues |
|
|
|
|
|