#include <iostream>
using namespace std;
#define MAX 2999
class Stack {
int top;
public:
int BSCS_Stack[MAX];
Stack() { top = -1; }
bool push(int x);
bool isEmpty();
int pop();
int peek();
};
bool Stack::push(int x)
{
if (top >= (MAX - 1)) {
cout << "Overflow";
return false;
}
else {
BSCS_Stack[++top] = x;
cout << x << " is pushed into the stack"<<endl;
return true;
}
}
int Stack::pop()
{
if (top < 0) {
cout << "Underflow";
return 0;
}
else {
int x = BSCS_Stack[top--];
return x;
}
}
int Stack::peek()
{
if (top < 0) {
cout << "The stack is Empty";
return 0;
}
else {
int x = BSCS_Stack[top];
return x;
}
}
bool Stack::isEmpty()
{
return (top < 0);
}
int main()
{
Stack s1;
s1.push(1);
s1.push(2);
s1.push(3);
s1.push(4);
return 0;
}
Comments
Leave a comment