Implementation of Stack using Arrays c++

 Implementation of Stack using Arrays c++

#include<iostream>
using namespace std;
#define Max 10
class Stack{
int top = -1;
public:
int stack[Max];
bool push(int val)
{
if (isFull())
{
cout << "Stack is full" << endl;
return false;
}
else
{
stack[++top] = val;
return true;
}
}
int pop()
{
if (isEmpty())
{
cout << "Stack is empty" << endl;
return 0;
}
else
{
int a = stack[top--];
return a;
}
}
bool isFull()
{
return (top > Max - 1);
}
bool isEmpty()
{
return (top < 0);
}
int peek()
{
if (isEmpty())
{
cout << "Stack is empty" << endl;
}
else
{
int a = stack[top];
return a;
}
}
};
int main()
{
Stack s1;
s1.push(5);
s1.push(2);
cout<<s1.pop();
getchar();
getchar();
return 0;
}

Comments

Popular posts from this blog

Multiple inheritance,friend function and multiple file in oop(object oriented programming)

Concepts of OOP (object oriented programming)

Concepts in c++........