-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack.cpp
63 lines (63 loc) · 960 Bytes
/
Stack.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include<bits/stdc++.h>
using namespace std;
int top=-1,st[5],_max=5,item;
void display()
{
if(top==-1)
{
cout << "Stack is Empty" << endl;
}
else
{
for(int i=0;i<=top;i++)cout << st[i] << " ";
cout<< endl;
}
}
void top_value()
{
cout << "Top value:: " << st[top] << endl;
}
void pop()
{
if(top==-1)
{
cout << "Empty" << endl;
return;
}
else
{
cout << "Deleted:: " << st[top] << endl;
top--;
}
}
void push()
{
if(top==_max)
{
cout << "Overflow" << endl;
return;
}
else
{
cin >> item;
top++;
st[top]=item;
}
}
int main()
{
int n;
while(1)
{
cin >> n;
if(n==1)push();
else if(n==2)pop();
else if(n==3)display();
else if(n==4)top_value();
else
{
cout << "Error" << endl;
continue;
}
}
}