#include<iostream>
using namespace std;
const int QueueSize = 100;
class CirQueue
{
public:
CirQueue();
void EnQueue(int x);
int DeQueue();
int GetHead();
private:
int data[QueueSize];
int front, rear;
};
CirQueue::CirQueue()
{
rear = front = QueueSize - 1;
}
void CirQueue::EnQueue(int x)
{
if ((rear + 1) % QueueSize == front)throw"上溢";
else
{
rear = (rear + 1) % QueueSize;
data[rear] = x;
}
}
int CirQueue::DeQueue()
{
if (rear == front)throw"下溢";
else
{
front = (front + 1) % QueueSize;
return data[front];
}
}
int CirQueue::GetHead()
{
if (rear == front)throw"下溢";
else
{
return data[(front + 1) % QueueSize];
}
}
int main()
{
CirQueue s;
cout << "对5和8进行入队操作" << endl;
s.EnQueue(5);
s.EnQueue(8);
cout << s.GetHead() << endl;
cout << s.DeQueue() << endl;
cout << s.GetHead() << endl;
}