In this sub-project, you will implement one class:
A stack stores elements in an ordered list and allows insertions and deletions at one end in O(1) time.
The elements in this stack are stored in an array. If the array is full, the bottom item is dropped from the stack. In practice, this would be equivalent to overwriting that entry in the array.
The run time of each member function is specified in parentheses at the end of the description. Projects which do not satisfy the run time requirements will be required to resubmit.
A class which implements a stack using an array. The capacity of the array is fixed at initialization time. For run-time requirements, the number of elements in the stack is n. The array is considered to be full if all entries in the array are assigned. If an insertion is made into a full stack, the element at the bottom is removed before the new element is inserted.
The class will have up to five members:
You may chose to use these or use whatever other member variables you want. You do not have to use all of these member variables—it is possible to implement this class using two of the three integer member variables; however, this requires more computation for the individual member functions.
Drop_off_stack( int n = 10 )
The constructor takes as an argument the capacity of the array and allocates memory for that array. The default initial capacity of the array is 10. Other class members are assigned as appropriate. (O(1))
~Drop_off_stack()
The destructor deletes the memory allocated for the array. (O(1))
Drop_off_stack( Drop_off_stack const & )
The copy constructor creates a new instance of the stack. (O(n))
This class has three accessors:
This class has five mutators:
The class has one friend: the operation cout << stack. Because the structure of the internal stack is unknown, nothing is implemented here; however, you could add an implementation which allows you to print the entries of your stack.