|
|
 |
|
|
|
|
171: return this;
172: }
173:
174: // I get all the credit and do none of the work
175: class LinkedList
176: {
177: public:
178: LinkedList();
179: ~LinkedList() { delete myHead; }
180: void Insert(Data * theData);
181: void ShowAll() const { myHead->Show(); }
182: private:
183: HeadNode * myHead;
184: };
185:
186: // At birth, i create the head node
187: // It creates the tail node
188: // So an empty list points to the head which
189: // points to the tail and has nothing between
190: LinkedList::LinkedList()
191: {
192: myHead = new HeadNode;
193: }
194:
195: // Delegate, delegate, delegate
196: void LinkedList::Insert(Data * pData)
197: {
198: myHead->Insert(pData);
199: }
200:
201: // test driver program
202: int main()
203: {
204: Data * pData;
205: int val;
206: LinkedList ll;
207:
208: // ask the user to produce some values
209: // put them in the list
210: for (;;)
211: {
212: cout << What value? (0 to stop): ;
213: cin >> val;
214: if (!val)
215: break;
216: pData = new Data(val);
217: ll.Insert(pData);
218: } |
|
|
|
 |
|
|
|
|
continues |
|
|
|
|
|