http://kid5.tistory.com/259


#pragma once

#include <iostream>

using namespace std;


template <class T, size_t SIZE>

class CircularQueue

{

public:

CircularQueue()

{

front = rear = 0;

}

void push_back(T d)

{

if (isFull()) throw;

data[rear] = d;

rear = (rear + 1) % SIZE;

}

void pop_front()

{

if (isEmpty()) throw;

front = (front + 1) % SIZE;

}

size_t size()

{

return front < rear ? rear - front : (rear + SIZE) - front;

}

void display()

{

cout << "data in the Queue : \n";

for (size_t i = 0, len = size(); i < len; ++i)

{

cout << data[(front + i) % SIZE] << endl;

}

}

bool isEmpty()

{

return front == rear;

}

bool isFull()

{

return front % SIZE == (rear + 1) % SIZE;

}

private:

int front;

int rear;

T data[SIZE];

};