|
|
 |
|
|
|
|
221: public:
222: LinkedList();
223: ~LinkedList() { delete myHead; }
224: void Insert(T * theObject);
225: void ShowAll() {myHead->Show(); }
226: private:
227: HeadNode<T> * myHead;
228: };
229:
230: // At birth, i create the head node
231: // It creates the tail node
232: // So an empty list points to the head which
233: // points to the tail and has nothing between
234: template <class T>
235: LinkedList<T>::LinkedList()
236: {
237: myHead = new HeadNode<T>;
238: }
239:
240: // Delegate, delegate, delegate
241: template <class T>
242: void LinkedList<T>::Insert(T * pObject)
243: {
244: myHead->Insert(pObject);
245: }
246:
247: // test driver program
248: int main()
249: {
250: Cat * pCat;
251: Data * pData;
252: int val;
253: LinkedList<Cat> ListOfCats;
254: LinkedList<Data> ListOfData;
255:
256: // ask the user to produce some values
257: // put them in the list
258: for (;;)
259: {
260: cout << What value? (0 to stop): ;
261: cin >> val;
262: if (!val)
263: break;
264: pCat = new Cat(val);
265: pData= new Data(val);
266: ListOfCats.Insert(pCat);
267: ListOfData.Insert(pData);
268: }
269: |
|
|
|
 |
|
|
|
|
continues |
|
|
|
|
|