#include <iostream>
using namespace std;
class Stack
{
private: int arr[5],top;
public:
Stack()
{
top = -1;
}
void push(int val)
{
if (top > 4)
cout << "Stack Overflow";
else
top++;
arr[top] = val;
}
int pop()
{
int temp;
if (top < 0)
cout << "Stack Underflow";
else
temp = arr[top];
top--;
return temp;
}
void print()
{
for (int i = 0; i <5; i++)
cout << arr[i];
}
};
int main()
{
int val,a;
Stack obj;
for(int i = 0; i < 5; i++)
{
cout << "Enter Number for Pushing: ";
cin >> val;
obj.push(val);
}
obj.print();
cout << endl;
cout<<"Popped Value is: "<<obj.pop();
cout << endl;
}
using namespace std;
class Stack
{
private: int arr[5],top;
public:
Stack()
{
top = -1;
}
void push(int val)
{
if (top > 4)
cout << "Stack Overflow";
else
top++;
arr[top] = val;
}
int pop()
{
int temp;
if (top < 0)
cout << "Stack Underflow";
else
temp = arr[top];
top--;
return temp;
}
void print()
{
for (int i = 0; i <5; i++)
cout << arr[i];
}
};
int main()
{
int val,a;
Stack obj;
for(int i = 0; i < 5; i++)
{
cout << "Enter Number for Pushing: ";
cin >> val;
obj.push(val);
}
obj.print();
cout << endl;
cout<<"Popped Value is: "<<obj.pop();
cout << endl;
}