// Implement stack, push(), pop(), empty?(), full?() #include using namespace std; class Stack { int a[50], top; public: Stack() { top = 0; } void push(int x) { if (top >= 50) return; a[top] = x; top++; } int pop() { if (top <= 0) return -1; int x = a[top - 1]; top--; return x; } bool empty() { return top == 0; } bool full() { return top != 0; } }; int main() { Stack s; int x, item, choice; while(true) { cout << "\n1. Push\n2. Pop\n3. Check if empty\n4. Check if full\n5. Quit\nSelect an option: "; cin >> choice; switch(choice) { case 1: cout << "Enter number of elements to enter: "; cin >> x; cout << "Enter " << x << " items for stack:\n"; for(int i = 0; i < x; i++) { cin >> item; s.push(item); } break; case 2: cout << "Enter number of elements to pop: "; cin >> x; for(int i = 0; i < x; i++) { cout << s.pop() << "\n"; } cout << x << " items popped from the stack.\n"; break; case 3: if(s.empty()) cout << "Stack is empty.\n"; else cout << "Stack is not empty.\n"; break; case 4: if(s.full()) cout << "Stack is full.\n"; else cout << "Stack is not full.\n"; break; case 5: cout << "Bye!\n"; return 0; } cout << "\n"; } return 0; }