< previous page page_417 next page >

Page 417
LISTING 23.2 continued
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
200:   // Nothing comes before the head so just
201:   // pass the Object on to the next node
202:   template <class T>
203:   Node<T> * HeadNode<T>::Insert(T * theObject)
204:   {
205:       myNext = myNext->Insert(theObject);
206:       return this;
207:   }
208:
209:   // I get all the credit and do none of the work
210:   template <class T>
211:   class LinkedList
212:   {
213:   public:
214:       LinkedList();
215:       ~LinkedList() { delete myHead; }
216:       void Insert(T * theObject);
217:       void ShowAll() { myHead->Show(); }
218:   private:
219:       HeadNode<T> * myHead;
220:   };
221:
222:   // At birth, i create the head node
223:   // It creates the tail node
224:   // So an empty list points to the head which
225:   // points to the tail and has nothing between
226:   template <class T>
227:   LinkedList<T>::LinkedList()
228:   {
229:       myHead = new HeadNode<T>;
230:   }
231:
232:   // Delegate, delegate, delegate
233:   template <class T>
234:   void LinkedList<T>::Insert(T * pObject)
235:   {
236:       myHead->Insert(pObject);
237:   }
238:
239:   void myFunction(LinkedList<Cat>& ListOfCats);
240:   void myOtherFunction(LinkedList<Data>& ListOfData);
241:
242:   // test driver program
243:   int main()
244:   {
245:       LinkedList<Cat>  ListOfCats;
246:       LinkedList<Data> ListOfData;
247:
248:       myFunction(ListOfCats);
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
continues

 
< previous page page_417 next page >

If you like this book, buy it!