STACK
STACK
#include<string>
class Stack {
private:
int top;
int arr[5];
public:
Stack() {
top = -1;
for (int i = 0; i < 5; i++) {
arr[i] = 0;
}
}
bool isEmpty() {
if (top == -1)
return true;
else
return false;
}
bool isFull() {
if (top == 4)
return true;
else
return false;
}
int pop() {
if (isEmpty()) {
cout << "stack underflow" << endl;
return 0;
} else {
int popValue = arr[top];
arr[top] = 0;
top--;
return popValue;
}
}
int count() {
return (top + 1);
}
void display() {
cout << "All values in the Stack are " << endl;
for (int i = 4; i >= 0; i--) {
cout << arr[i] << endl;
}
}
};
int main() {
Stack s1;
int option, postion, value;
do {
cout << "What operation do you want to perform? Select Option number. Enter 0
to exit." << endl;
cout << "1. Push()" << endl;
cout << "2. Pop()" << endl;
cout << "3. isEmpty()" << endl;
cout << "4. isFull()" << endl;
cout << "5. peek()" << endl;
cout << "6. count()" << endl;
cout << "7. change()" << endl;
cout << "8. display()" << endl;
cout << "9. Clear Screen" << endl << endl;
return 0;
}