class StackY
{
private:
int maxSize;
int *stackArray;
int top;
public:
StackY(int s);
~StackY();
void push(int j);
int pop();
int peek();
bool isEmpty();
bool isFull();
}
StackY::StackY(int s)
{
maxSize=s;
stackArray = new int[maxSize];
top=-1;
}
void StackY::push(int j)
{
if(isFull())
cout<<"Stack is full cannot insert";
else
stackArray[++top]=j;
}
int StackY::pop()
{
if (isEmpty())
{
cout<<"The Stack is empty";
return -999;
}
else
return stackArray[top--];
}
int StackY::peek()
{
if(top==-1)
{
cout<<"The stack is empty";
return stackArray[top];
}
else
return stackArray[top];
}
bool StackY::isEmpty()
{
if( top==-1) return 1; else return 0;
}
bool StackY::isFull
{
if (top == maxSize) return 1; else return 0;
}
int StackY::peek()
{
if (top==-1)
{
cout<<"The stack is empty";
return -999;
}
else
return stackArray[top];
}
No comments:
Post a Comment
“What do you think about this?”
“Do you agree?
Share your thoughts in the comments below!”