< previous page page_408 next page >

Page 408
LISTING 23.1 continued
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
123:    template <class T>
124:    InternalNode<T>::InternalNode(T * theObject, Node<T> * next):
125:    myObject(theObject),myNext(next)
126:    {
127:    }
128:
129:    // the meat of the list
130:    // When you put a new object into the list
131:    // it is passed to the node which figures out
132:    // where it goes and inserts it into the list
133:    template <class T>
134:    Node<T> * InternalNode<T>::Insert(T * theObject)
135:    {
136:
137:       // is the new guy bigger or smaller than me?
138:       int result = myObject->Compare(*theObject);
139:
140:
141:       switch(result)
142:       {
143:          // by convention if it is the same as me it comes first
144:       case kIsSame:        // fall through
145:       case kIsLarger:      // new Object comes before me
146:           {
147:               InternalNode<T> * ObjectNode =
148:               new InternalNode<T>(theObject, this);
149:               return ObjectNode;
150:           }
151:
152:           // it is bigger than I am so pass it on to the next
153:           // node and let HIM handle it.
154:       case kIsSmaller:
155:               myNext = myNext->Insert(theObject);
156:               return this;
157:       }
158:       return this; // appease MSC
159:    }
160:
161:
162:    // Tail node is just a sentinel
163:    template <class T>
164:    class TailNode : public Node<T>
165:    {
166:    public:
167:       TailNode(){}
168:       virtual ~TailNode(){}
169:       virtual Node<T> * Insert(T * theObject);
170:       virtual void Show() { }
171:
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
continues

 
< previous page page_408 next page >

If you like this book, buy it!