In this sub-project, you will implement on class:
A linked stack 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 stack (in fact, two stacks) which has the specified behaviours. For run-time requirements, the number of elements in the stack is n.
The class has four member variables:
Each array in the linked list will have a capacity of eight. When the stack is empty, the linked list is empty. As objects are placed into the stack, 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 stack and then push five times and pop once. The result will appear as shown in Figure 1 where the member variables itop = 3.
Figure 1. The stack after five pushes and one pop.
Now, suppose that there is a sequence of fifteen 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 variable itop keeps track of the location in the top in the front array. As shown in Figure 2, itop = 2 and the linked list has three entries.
Figure 2. The stack in Figure 1 after another fifteen pushes.
Suppose next there is a sequence of ten pops. After the third 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 itop would be reset to one less than the array capacity. After seve more pops, itop = 0, as shown in Figure 3.
Figure 3. The stack in Figure 2 after ten pops.
The default constructor is used.
Make a complete copy of the linked stack. 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.