< previous page page_409 next page >

Page 409
LISTING 23.1 continued
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
172:    private:
173:
174:    };
175:
176:    // If Object comes to me, it must be inserted before me
177:    // as I am the tail and NOTHING comes after me
178:    template <class T>
179:    Node<T> * TailNode<T>::Insert(T * theObject)
180:    {
181:        InternalNode<T> * ObjectNode =
182:        new InternalNode<T>(theObject, this);
183:        return ObjectNode;
184:    }
185:
186:    // Head node has no Object, it just points
187:    // to the very beginning of the list
188:    template <class T>
189:    class HeadNode : public Node<T>
190:    {
191:    public:
192:       HeadNode();
193:       virtual ~HeadNode() { delete myNext; }
194:       virtual Node<T> * Insert(T * theObject);
195:       virtual void Show() { myNext->Show(); }
196:    private:
197:       Node<T> * myNext;
198:    };
199:
200:    // As soon as the head is created
201:    // it creates the tail
202:    template <class T>
203:    HeadNode<T>::HeadNode()
204:    {
205:        myNext = new TailNode<T>;
206:    }
207:
208:    // Nothing comes before the head so just
209:    // pass the Object on to the next node
210:    template <class T>
211:    Node<T> * HeadNode<T>::Insert(T * theObject)
212:    {
213:        myNext = myNext->Insert(theObject);
214:        return this;
215:    }
216:
217:    // I get all the credit and do none of the work
218:    template <class T>
219:    class LinkedList
220:    {
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
continues

 
< previous page page_409 next page >

If you like this book, buy it!