-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue.cpp
More file actions
54 lines (45 loc) · 950 Bytes
/
Copy pathQueue.cpp
File metadata and controls
54 lines (45 loc) · 950 Bytes
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
#include <iostream>
using namespace std;
class Queue {
private:
int* arr;
int front, rear, size, capacity;
public:
Queue(int cap) {
capacity = cap;
arr = new int[capacity];
front = 0;
size = 0;
rear = -1;
}
bool isEmpty() {
return size == 0;
}
bool isFull() {
return size == capacity;
}
void enqueue(int x) {
if (isFull()) {
cout << "Queue Full\n";
return;
}
rear = (rear + 1) % capacity;
arr[rear] = x;
size++;
}
void dequeue() {
if (isEmpty()) {
cout << "Queue Empty\n";
return;
}
front = (front + 1) % capacity;
size--;
}
int getFront() {
if (isEmpty()) return -1;
return arr[front];
}
int getSize() {
return size;
}
};