-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue using array
More file actions
67 lines (59 loc) · 1.06 KB
/
Queue using array
File metadata and controls
67 lines (59 loc) · 1.06 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
#include <bits/stdc++.h>
class Queue {
public:
int front1;
int rear;
int size;
int *arr;
Queue()
{
front1=0;
rear=0;
size=100001;
arr=new int[size];
}
/*----------------- Public Functions of Queue -----------------*/
bool isEmpty()
{
return (front1==rear) ? true : false;
}
void enqueue(int data)
{
if(rear==size)
{
cout<<"Queue is full ";
return ;
}
arr[rear]=data;
rear++;
}
int dequeue()
{
if(front1==rear)
{
return -1;
}
else
{
int element=arr[front1];
arr[front1]==-1;
front1++;
if(front1==rear)
{
front1=0;
rear=0;
}
return element;
}
}
int front() {
if(front1==rear)
{
return -1;
}
else
{
return arr[front1];
}
}
};