-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStack.cpp
More file actions
78 lines (78 loc) · 1.48 KB
/
Stack.cpp
File metadata and controls
78 lines (78 loc) · 1.48 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
78
#include<iostream>
using namespace std;
struct stack
{
int top,items[10];
};
void disp(stack *s)
{
cout<<"\nDisplaying Stack: ";
for(int i=0;i<=s->top;i++)
cout<<s->items[i]<<",";
}
int isFull(stack *s)
{
if(s->top==10)
return true;
else
return false;
}
int isEmpty(stack *s)
{
if(s->top<=-1)
return true;
else
return false;
}
void push(stack *s,int x)
{
s->top+=1;
s->items[s->top]=x;
}
int pop(stack *s)
{
int temp=s->items[s->top];
s->top--;
return temp;
}
int main()
{
int ch,x,k=0;
stack s;
s.top=-1;
cout<<"STACK\n\n Choose the option\n";
while(k==0)
{
cout<<"\n\n1.Push\n2.Pop\n3.Display\n4.Exit\n\n";
cin>>ch;
switch(ch)
{
case 1:
if(!(isFull(&s)))
{
cout<<"\nEnter the number to push : ";
cin>>x;
push(&s,x);
}
else
cout<<"Stack Overflow";
break;
case 2:
if(!(isEmpty((&s))))
cout<<"popped : "<<pop(&s);
else
cout<<"Stack Underflow";
break;
case 3:
disp(&s);
break;
case 4:
k=5;
break;
default:
cout<<"Wrong input";
break;
}
}
return 0;
}