-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue Code.cpp
More file actions
105 lines (84 loc) · 1.19 KB
/
Queue Code.cpp
File metadata and controls
105 lines (84 loc) · 1.19 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<bits/stdc++.h>
using namespace std;
int q[5],max_size=5;
int f=-1,rear=-1;
void push(int value)
{
if((rear+1)%max_size==f)
{
cout<<"Overflow"<<endl;
return;
}
if(f==-1 && rear == -1)
{
f=0;
rear=0;
q[rear]=value;
}
else
{
rear++;
rear=rear%max_size;
q[rear]= value;
}
}
void pop()
{
if(f==-1 && rear == -1)
{
cout<<"Underflow"<<endl;
return;
}
if(f==rear)
{
f=-1;
rear=-1;
}
else
{
f++;
f=f%max_size;
}
}
int ret_front()
{
return q[f];
}
bool empty1()
{
if(f==-1 && rear == -1)
{
return true;
}
else
return false;
}
int main()
{
// queue<int> q;
// q.push(10);
// q.push(20);
// q.push(30);
//
// q.push(112);
//
// while(!q.empty())
// {
// cout<<q.front()<<endl;
// q.pop();
// }
push(10);
push(20);
push(30);
push(40);
push(50);
pop();
pop();
push(60);
push(70);
while(!empty1())
{
cout<<ret_front()<<endl;
pop();
}
}