-
Notifications
You must be signed in to change notification settings - Fork 293
/
queue all operations
97 lines (78 loc) · 1.46 KB
/
queue all operations
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
#include<iostream>
using namespace std;
struct stack
{
int r;
int f;
int size=10;
int a[10];
};
void enque(struct stack *p,int data)
{
if(p->r==p->size-1)
{
cout<<"stack is over flow"<<endl;
}
else
{
p->r++;
p->a[p->r]=data;
if(p->f==-1)
{
p->f=0;
}
}
}
void deque(struct stack *p)
{
if(p->r==p->f)
{
cout<<"stack is empty right now"<<endl;
}
else
{
p->f++;
cout<<"Deleted element is "<<p->a[p->f-1]<<endl;
}
}
void display(struct stack *p)
{
int c=p->f;
int d=p->r;
for(int i=c;i<=d;i++)
{
cout<<p->a[i]<<endl;
}
}
int main()
{
struct stack s;
s.r=-1;
s.f=-1;
int n;
while(1)
{
cout<<"-----------------------------------"<<endl;
cout<<"enter the number "<<endl<<"1)enque operation"<<endl<<"2)deque operation"<<endl<<"3)display"<<endl<<"4)exit"<<endl;
cout<<"-----------------------------------\n"<<endl;
cin>>n;
switch(n)
{
case 1:
int r;
cout<<"enter the number"<<endl;
cin>>r;
enque(&s,r);
break;
case 2:
deque(&s);
break;
case 3:
display(&s);
break;
case 4:
exit(0);
}
}
return 0;
}