A stack is a linear data structure which enables the user to add and remove integers from one end only, using the concept of LIFO(Last In First Out). An array containing the marks of 50 students in ascending order is to be pushed into the stack.
Define a class Array_to_Stack with the following details:
Class name: Array to Stack Data members/instance variables:
m[]: to store the marks
st[ ]: to store the stack elements
cap: maximum capacity of the array and stack
top: to point the index of the topmost element of the stack
Methods/Member functions:
Array_to_Stack(int n): parameterized constructor to initialize cap = n and top = -1
void input_marks(): to input the marks from the user and store it in the array m[ ] in ascending order and simultaneously push the marks into the stack st[ ] by invoking the function pushmarks()
void pushmarks(int v): to push the marks into the stack at top location if possible, otherwise, display “not possible”
intpopmarks(): to return marks from the stack if possible, otherwise, return-999
void display(): To display the stack elements
Specify the class Array_to_Stack, giving the details of the constructor(int), void input_marks(), void pushmarks(int), int popmarks() and void display().
The main function and the algorithm need not be written.