bool LessThan(const Book & lhs, const Book & rhs) // post: returns true if lowAge of lhs < l;owAge of rhs or // if lowAge of lhs and rhs are equal and highAge of lhs // is less than highAge of rhs; // otherwise, returns false { if ((lhs.lowAge < rhs.lowAge) || (lhs.lowAge == rhs.lowAge && lhs.highAge < rhs.highAge)) return true; return false; } void BookList::InsertOne(const Book & bk) // pre: this BookList is in sorted order by age range as defined by // LessThan // bk is not already in this BookList // post: bk has been inserted into this BookList, maintaining // its order by age range { if (myCount >= myList.length()) myList.resize(myList.length()*2); int k = 0; while (k < myCount && LessThan(myList[k], bk)) k++; for (int j = myCount; j > k; j--) myList[j] = myList[j-1]; myList[k] = bk; myCount++; } void BookList::InsertMany(const apvector & second) // pre: this BookList is in sorted ordered by age range as defined by // LessThan; second contains second.length() books in // arbitrary order; none of the books in second are in // this BookList // post: all the books from second have been inserted into this // BookList, maintaining is order by age range. { for (int k = 0; k < second.length(); k++) InsertOne(second[k]); }