A stack is a kind of data structure which can store elements with the restriction that an element can be added or removed from the top only.
The details of the class Stack is given below:
Class name: Stack
Data members/instance variables:
st[]: the array to hold the names
size: the maximum capacity of the string array
top: the index of the topmost element of the stack
ctr: to count the number of elements of the stack Member functions:
Stack( ): default constructor
Stack(int cap): constructor to initialize size = cap and top = -1
void pushname(String n): to push a name onto the stack. If the stack is full, display
the message “OVERFLOW”
String popname(): removes a name from the top of the stack and returns it.
If the stack is empty, display the message “UNDERFLOW”
void display(): Display the elements of the stack
Specify class Stack giving details of the constructors(), void pushname(String n), String popname() and void display().
THE MAIN() FUNCTION AND ALGORITHM NEED NOT BE WRITTEN.