Skip to content

Instantly share code, notes, and snippets.

@miladabc
Created July 7, 2018 16:30
Show Gist options
  • Save miladabc/e4637bf64b02b0a2c1cc4767550fdce8 to your computer and use it in GitHub Desktop.
Save miladabc/e4637bf64b02b0a2c1cc4767550fdce8 to your computer and use it in GitHub Desktop.
Circular Queue implementation with Array
//Milad Abbasi
//06-07-2018
//Circular Queue implementation with Array
#include <iostream>
#define MAX 5
using namespace std;
class CQueue
{
private:
int cQueue[MAX];
int front, rear;
public:
CQueue()
{
rear = front = 0;
}
void enQueue(int value)
{
rear = (rear + 1) % MAX;
if (isEmpty())
{
cout<<"Queue Overflow \n";
rear = MAX - 1;
return;
}
cQueue[rear] = value;
}
int deQueue()
{
if(isEmpty())
{
cout<<"Queue Underflow \n";
return -1;
}
front = (front + 1) % MAX;
return cQueue[front];
}
int peek()
{
return cQueue[front + 1];
}
bool isEmpty()
{
return front == rear;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment