#include <iostream>
#include <assert.h>
enum
{
MAX_SIZE = 3
};
template<typename T>
class MyQueue
{
T Array_[MAX_SIZE];
size_t Count_ = 0;
size_t Front_ = 0;
size_t Rear_ = 0;
public:
void Enqueue(T Data)
{
if (true == IsFull())
{
assert(false);
}
Array_[Rear_] = Data;
Rear_ = (Rear_ + 1) % MAX_SIZE; //원형 큐
++Count_;
}
bool IsFull()
{
return Front_ == (Rear_ + 1) % MAX_SIZE;
}
bool IsEmpty()
{
return Front_ == Rear_;
}
T Dequeue()
{
if (true == IsEmpty())
{
assert(false);
}
T Temp = Array_[Front_];
Array_[Front_] = T();
Front_ = (Front_ + 1) % MAX_SIZE;
--Count_;
return Temp;
}
};
int main()
{
MyQueue<int> queue;
for (int i = 0; i < 5; ++i)
{
queue.Enqueue(i * 2);
}
for (int i = 0; i < 5; ++i)
{
int a = queue.Dequeue();
}
}