In this sub-project, you will implement on class:
A linked queue may be implemented using the linked list from Project 1 which allows appropriate insertions and deletions in O(1) time. If your Project 1 did not work, you are welcome to use the implementation of a friend—only you must acknowledge that individual.
The run time of each member function is specified in parentheses at the end of the description.
A class which implements a linked queue (in fact, two stacks) which has the specified behaviours. For run-time requirements, the number of elements in the queue is n.
The class has four member variables:
Each array in the linked list will have a capacity of eight. When the queue is empty, the linked list is empty. As objects are placed into the queue, they are placed into the arrays that will be stored in the linked list. As necessary, additional arrays are added to the linked list. For example, suppose we begin with an empty queue and then push six times and pop once. The result will appear as shown in Figure 1 where the member variables ifront = 1 and iback = 5.
Figure 1. The queue after six pushes and one pop.
Now, suppose that there is a sequence of fourteen pushes: when the array at the back of the linked list is filled, a new array is pushed onto the back of the linked list, and new entries are pushed into the array pointed to by that node. When this array also becomes filled, another array will be pushed onto the linked list. The member variables ifront and iback keep track of the locations in the first and last entries in their respective arrays. As shown in Figure 2, ifront = 1 and itail = 3 and the linked list has three entries.
Figure 2. The queue in Figure 1 after another fourteen pushes.
Suppose next there is a sequence of nine pops. After the seventh pop, the node at the front of the linked list would be popped and the memory for the array it points to would be deallocated and ifront would be reset to 0. After two more pops, ifront = 2, as shown in Figure 3.
Figure 3. The queue in Figure 2 after nine pops.
The default constructor is used.
Make a complete copy of the linked queue. For each array in the original linked list, a new array must be allocated and the entries copied over.
The destructor will have to empty the linked list and deallocate the memory pointed to by the entries of the linked list.
This class has three accessors:
This class has four mutators:
The class has no friends.