

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


#include
void STACK::displayItems() { cout << "STACK is: "; for (int i = top; i >= 0; i--) cout << num[i] << " "; cout << endl; } int main() { STACK stk; int choice, n, temp; do { cout << "\n0 - Exit." << endl; cout << "1 - Push Item." << endl; cout << "2 - Pop Item." << endl; cout << "3 - Display Items (Print STACK)." << endl; cout << "Enter your choice: "; cin >> choice; switch (choice) { case 0: break; case 1: cout << "Enter item to insert: "; cin >> n; temp = stk.push(n); if (temp == -1) cout << "STACK is FULL." << endl; else cout << temp << " inserted." << endl; break; case 2: temp = stk.pop(); if (temp == -1) cout << "STACK IS EMPTY." << endl; else cout << temp << " is removed (popped)." << endl; break; case 3: stk.displayItems(); break; default: cout << "An Invalid choice." << endl; } } while (choice != 0); return 0; }