-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstacks.cpp
More file actions
77 lines (77 loc) · 1.1 KB
/
Copy pathstacks.cpp
File metadata and controls
77 lines (77 loc) · 1.1 KB
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
75
76
77
#include<iostream>
using namespace std;
class stack
{
int st[10];
int max=10,top=-1;
public:
void push(int);
void pop();
void display();
};
void stack::push(int x)
{
if(top==max)
{
cout<<"overflow condition\n";
}
else
{
top++;
st[top]=x;
}
}
void stack::pop()
{
int item;
if(top==-1)
{
cout<<"underflow condition\n";
}
else
{
item=st[top];
cout<<item<<"\n";
top--;
}
}
void stack::display()
{
if(top==-1)
{
cout<<"stack is empty\n";
}
else
{
for (int i=top;i>-1;i--)
{
cout<<"\t"<<st[i];
}
cout<<"\n";
}
}
int main()
{
int n,x;
stack s;
option: cout<<"enter the number against the menu to avail that service\n1. pushing an element into the stack\n2. poping an element from the stack\n3. displaying stack\n4. exit\n";
cin>>n;
switch(n)
{
case 1: cin>>x;
s.push(x);
goto option;
break;
case 2: s.pop();
goto option;
break;
case 3: s.display();
goto option;
break;
case 4: cout<<"exit\n";
break;
default: cout<<"invalid option\n";
break;
}
return 0;
}