Modify the Package class in the solution of Exercise 12-6 so that it contains an additional pointer to the previous object in the list. This makes it a so-called doubly-linked list—naturally, the data...


Modify the Package class in the solution of Exercise 12-6 so that it contains an additional pointer to the previous object in the list. This makes it a so-called doubly-linked list—naturally, the data structure we were using before is called a singly-linked list. Modify the Package, Truckload, and Iterator classes to make use of this, including providing the ability to iterate through Box objects in the list in reverse order and to list the objects in a Truckload object in reverse sequence. Devise a main() program to demonstrate the new capabilities.


A scrutinous analysis of the main() function of Ex12_17 (and thus also that of Ex12_18 and the solutions of the previous two exercises) reveals the following performance flaw: To remove the largest Box, we perform two linear traversals of the linked list. First we look for the largest Box, and then we look inside removeBox() to look for the Package to unlink. Devise a solution based on the Iterator class of Exercise 12-7 to avoid this second search. Hint: The solution hinges on a member function with the following signature:


bool removeBox(Iterator iterator);




May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here