-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcircular_que.cpp
55 lines (53 loc) · 1.35 KB
/
circular_que.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
#include <iostream>
using namespace std;
int t=-1;
int f=-1;
int main()
{
cout<<"Enter the length of the circular que:\n";
int l;
cin >> l;
int a[l];
int n=0;
int count=0;
while(n==0)
{
cout<<"Enque:1 , deque:2 , display:3 , exit:4"<<endl;
int in ;
cin >> in;
switch (in)
{
case 1:
if((t+1)%l==f and f!=t) cout<<"Que Full! \n";
else
{
if(f==-1) f++;
t=(t+1)%l;
cin>>a[t];
}
break;
case 2:
if(f==t)
{
f=-1;t=-1;
}
if (f==-1) cout<<"Que Empty! \n";
else
{
f=(f+1)%l;
}
break;
case 3:
if (f!=-1){
for (int i=f;i!=t;i=(i+1)%l)
{
cout<<a[i]<<" ";
}
cout<<a[t];
cout<<endl;}
else cout<<"Que Empty! \n";
break;
case 4: exit(0);
}
}
}