Simple Queue
#include <bits/stdc++.h>
class Queue {
int *arr;
int size;
int qfront, rear, element;
public:
Queue() {
size = 1024;
arr = new int [size];
qfront = element = rear = 0;
}
/*----------------- Public Functions of Queue -----------------*/
bool isEmpty() {
return element == 0;
}
bool isFull() {
return rear == size-1;
}
void enqueue(int data) {
if(isFull())
return ;
element++;
arr[rear++] = data;
}
int dequeue() {
if(isEmpty())
return -1;
element--;
return arr[qfront++];
}
int front() {
if(isEmpty())
return -1;
return arr[qfront];
}
};
Last updated
Was this helpful?