#include <iostream.h>
#include <conio.h>
#include <iomanip.h>
#include <queue>
using namespace std;
template <class T>
class SeqQueue:public queue<T>
{
public:
SeqQueue(int mSize) ;
~SeqQueue() {delete[]q;};
bool IsEmpty() const{return front ==rear;};
bool IsFull() const{return(rear+1)%maxSize==front;};
bool Front(T& x) const;
bool EnQueue(T x);
bool DeQueue();
void Clear() {front=rear=0;};
/*private:*/
int front,rear;
int maxSize;
T *q;
};
template<class T>
SeqQueue<T>::SeqQueue(int mSize)
{
maxSize=mSize;
q=new T[maxSize];
front=rear=0;
}
/* 取队首*/
template<class T>
bool SeqQueue<T>::Front(T& x) const
{
if (IsEmpty())
{
cout<<"empty"<<endl;return false;
}
x=q[(front+1)%maxSize];return true;
}
/* 入队*/
template<class T>
bool SeqQueue<T>::EnQueue(T x)
{
if(IsFull())
{
cout<<"full"<<endl;return false;
}
/*q[(rear+1)%maxSize]=x;*/
rear=(rear+1)%maxSize;
q[rear]=x;return true;
}
/* 出队*/
template<class T>
bool SeqQueue<T>::DeQueue()
{
if(IsEmpty())
{
cout<<"underflow"<<endl;return false;
}
front=(front+1)%maxSize;return true;
}
void main()
{
SeqQueue<int> que1(5);
que1.EnQueue(1);
que1.EnQueue(2);
que1.EnQueue(3);
que1.EnQueue(4);
for (int i=1;i<5;i++)
{
cout<<que1.q[i]<<endl;
}
que1.DeQueue();
cout<<"删除队尾元素"<<endl;
for (i=1;i<4;i++)
{
cout<<que1.q[i]<<endl;
}
}