-
Notifications
You must be signed in to change notification settings - Fork 3
/
Stack.cpp
74 lines (68 loc) · 885 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
64
65
66
67
68
69
70
71
72
73
74
// Implement Stack Data Structure
#include<iostream>
void push(int);
void pop();
void show();
int stack[10] = {0,0,0,0,0,0,0,0,0,0}, top = -1;
using namespace std;
int main()
{
int i;
do
{
cout << "\n[1] Push";
cout << "\n[2] Pop";
cout << "\n[3] Show Stack";
cout << "\n[0] Exit\n";
cin >> i;
if(i == 1)
{
int item;
cout << "\nEnter New Value :\n";
cin >> item;
push(item);
}
else if(i == 2)
{
pop();
}
else if(i == 3)
{
show();
}
}while(i != 0);
}
void push(int i)
{
if(top == 9)
{
cout << "\n**Stack Full**";
}
else
{
top++;
stack[top] = i;
cout << "\n**Item Pushed in the Stack**";
}
}
void pop()
{
if(top == -1)
{
cout << "\n**Stack Empty**";
}
else
{
stack[top] = 0;
top--;
cout << "\n**Item Popped**";
}
}
void show()
{
for(int i = 0; i < 10; i++)
{
cout << stack[i] << " ";
}
cout << "\nTop->" << top;
}