Sams Teach Yourself C++ in 21 Days

(singke) #1
188: if (pNode->itsPart->GetPartNumber() == PartNumber)
189: break;
190: }
191: if (pNode == NULL)
192: return NULL;
193: else
194: return pNode->itsPart;
195: }
196:
197: void PartsList::Iterate(void (Part::*func)()const) const
198: {
199: if (!pHead)
200: return;
201: PartNode* pNode = pHead;
202: do
203: (pNode->itsPart->*func)();
204: while (pNode = pNode->itsNext);
205: }
206:
207: void PartsList::Insert(Part* pPart)
208: {
209: PartNode * pNode = new PartNode(pPart);
210: PartNode * pCurrent = pHead;
211: PartNode * pNext = 0;
212:
213: int New = pPart->GetPartNumber();
214: int Next = 0;
215: itsCount++;
216:
217: if (!pHead)
218: {
219: pHead = pNode;
220: return;
221: }
222:
223: // if this one is smaller than head
224: // this one is the new head
225: if (pHead->itsPart->GetPartNumber() > New)
226: {
227: pNode->itsNext = pHead;
228: pHead = pNode;
229: return;
230: }
231:
232: for (;;)
233: {
234: // if there is no next, append this new one
235: if (!pCurrent->itsNext)
236: {
237: pCurrent->itsNext = pNode;

576 Day 16


LISTING16.7 continued
Free download pdf