Advanced Inheritance 559
16
240: return;
241: }
242:
243: // if this goes after this one and before the next
244: // then insert it here, otherwise get the next
245: pNext = pCurrent->GetNext();
246: Next = pNext->GetPart()->GetPartNumber();
247: if (Next > New)
248: {
249: pCurrent->SetNext(pNode);
250: pNode->SetNext(pNext);
251: return;
252: }
253: pCurrent = pNext;
254: }
255: }
256:
257: class PartsCatalog
258: {
259: public:
260: void Insert(Part *);
261: int Exists(int PartNumber);
262: Part * Get(int PartNumber);
263: operator+(const PartsCatalog &);
264: void ShowAll() { thePartsList.Iterate(Part::Display); }
265: private:
266: PartsList thePartsList;
267: };
268:
269: void PartsCatalog::Insert(Part * newPart)
270: {
271: int partNumber = newPart->GetPartNumber();
272: int offset;
273:
274: if (!thePartsList.Find(offset, partNumber))
275: {
276: thePartsList.Insert(newPart);
277: }
278: else
279: {
280: cout << partNumber << “ was the “;
281: switch (offset)
282: {
283: case 0: cout << “first “; break;
284: case 1: cout << “second “; break;
285: case 2: cout << “third “; break;
286: default: cout << offset+1 << “th “;
287: }
288: cout << “entry. Rejected!” << endl;
289: }
290: }
291:
LISTING16.5 continued