-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueueca.cpp
More file actions
105 lines (102 loc) · 1.37 KB
/
queueca.cpp
File metadata and controls
105 lines (102 loc) · 1.37 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
100
101
102
103
104
105
#include<iostream>
using namespace std;
int counter=0;
class queue
{
public:
int front=0;
int rear=0;
int arr[6];
enque(int a)
{
if(counter!=6)
{
if(front==6)
{
front=0;
arr[front]=a;
front++;
counter++;
}
else
{
arr[front]=a;
front++;
counter++;
}
}
else
cout<<"\nOverflow";
}
deque()
{
if(counter!=0)
{
if(rear==5)
rear=0;
else
rear++;
counter--;
}
else
cout<<"\nEmpty";
}
int peek()
{
if(counter!=0)
return arr[rear];
else cout<<"\n Empty";
}
void display()
{
if(rear<front)
{
for(int i=rear;i<front;i++)
cout<<" "<<arr[i];
}
else
{
for(int i=rear;i<6;i++)
cout<<" "<<arr[i];
for(int i=0;i<front;i++)
cout<<" "<<arr[i];
}
}
};
int main()
{
int i,j;
queue q;
do
{
cout<<"\nPRESS CORRECT OPTION 1.enque 2.deque 3.peek 4.display 5.exit\n";
cin>>i;
switch(i)
{
case 1:
{
cout<<"\nEnter any number:";
cin>>j;
q.enque(j);
break;
}
case 2:
{
q.deque();
break;
}
case 3:
{
cout<<q.peek();
break;
}
case 4:
{
q.display();
break;
}
default:
cout<<" ";
}
}while(i!=5);
}