Comp 121 Introduction to Data Structures.
Spring 2000Programming Assignment 2 -- Due March 9, 2000
Objective: To gain further experience in implementing abstract data types (ADTs). To design and implement a non-trivial algorithm.
Goal. To implement the enhancedStack ADT as an object template in C++.
The enhanced stack abstract data type is specified as follows:
AbstractDataType enhancedStack{
Instances: finite collections of zero or more elements
Operations:
Create(n):
Create an empty enhancedStack capable of holding n elementsDestroy( )
: Erase an enhancedStackIsEmpty( ):
Return true if the enhancedStack is empty; false otherwiseIsFull( ):
Return true if the enhancedStack is full; false otherwisepush(x):
Insert the element x into the enhancedStacktop( ):
Return the last element inserted into the enhancedStackpop( ):
Delete the last element inserted from the enhancedStack, and return this deleted elementMin( ):
Return the smallest element in the enhancedStacknextMin( ):
Return the second-smallest element in the enhancedStack}
You are to implement this ADT in the C++ programming language. I.e., you are to define a class template
template enhancedStack <class T>{
.
.
};
such that declarations (known as "instantiations" of the class template) of the form
enhancedStack <int> S1(10);
enhancedStack <myClass> S2(25);
would create an instance S1 of a enhancedStack capable of holding 10 integers, and an instance S2 of a enhancedStack that is capable of holding 25 myClass objects (where "myClass" is an object that you have previously defined).
Algorithms/ data structures. Implement your enhancedStack using what the text calls "formula-based representation." (I.e., use arrays rather than linked lists.) Your implementation must be Q (1) i.e.,take constant time per operation.
Rules for submitting this (and future) programs: