//Write a program to implement stack using arrays #include using namespace std; #define MAX 5 class Stack { int top; public: int a[MAX]; Stack() { top = -1; } bool push(int x); int pop(); int peek(); bool isEmpty(); }; bool Stack::push(int x) { if (top >= (MAX - 1)) { cout << "Stack Overflow\n"; return false; } else { a[++top] = x; cout << x << " pushed into stack\n"; return true; } } int Stack::pop() { if (top < 0) { cout << "Stack Underflow\n"; return 0; } else { int x = a[top--]; return x; } } int Stack::peek() { if (top < 0) { cout << "Stack is Empty\n"; return 0; } else { int x = a[top]; return x; } } bool Stack::isEmpty() { return (top < 0); } int main() { class Stack s; ///inputs taken from users int numelements; cout << "Enter the number of elements to be pushed into stack.\n"; cin >> numelements; //while(numelements>MAX){ // cout << "Number" //} cout<< "Enter: "<>elements; s.push(elements); } //s.push(10); //s.push(20); //s.push(30); int numtopop; cout << "\n Enter the number of elements pop: "; cin >> numtopop; cout << " Elements popped from stack: \n"; for(int i=0; i