Created
July 7, 2018 16:30
-
-
Save miladabc/e4637bf64b02b0a2c1cc4767550fdce8 to your computer and use it in GitHub Desktop.
Circular Queue implementation with Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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