-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcharacter stack.cpp
More file actions
99 lines (99 loc) · 1.71 KB
/
character stack.cpp
File metadata and controls
99 lines (99 loc) · 1.71 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include<iostream>
using namespace std;
#define size 10
struct stack
{
int top;
char items[size];
};
void disp(stack *s)
{
int i;
cout<<"\nDisplaying Stack: ";
for(i=0;i<=s->top;i++)
{
cout<<s->items[i]<<",";
}
}
int isFull(stack *s)
{
if(s->top==size)
{
return true;
}
else
{
return false;
}
}
int isEmpty(stack *s)
{
if(s->top<=-1)
{
return true;
}
else
{
return false;
}
}
void push(stack *s,char x)
{
s->top+=1;
s->items[s->top]=x;
}
char pop(stack *s)
{
char temp=s->items[s->top];
s->top--;
return temp;
}
int main()
{
int ch,k=0;
char x;
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;
}
}
cout<<"\n\n\n\nEND!";
return 0;
}