帮忙看看有什么错误!谢谢啊!
#include<iostream.h>
enum ResultCode {Underflow,Overflow};
template<class T>
class Queue
{
public:
virtual void Append(const T &x)=0;
virtual void Serve()=0;
virtual T Front()const=0;
virtual bool IsEmpty() const=0;
virtual bool IsFull() const=0;
};
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;
}
void Clear(){front=rear=0;}
void Append(const T& x);
void Serve();
void Output(ostream& out);
T Front()const;
private:
T *q;
int maxSize;
int front,rear;
void Output(ostream& out)const;
friend ostream &operator<<(ostream & out,const SeqQueue<T>& q);
};
template<class T>
SeqQueue<T>::SeqQueue(int mSize)
{
maxSize=mSize+1;
q=new T[maxSize];
front=rear=0;
}
template<class T>
void SeqQueue<T>::Append(const T&x)
{
if(IsFull()) throw Overflow;
q[rear=(rear+1)%maxSize]=x;
}
template<class T>
void SeqQueue<T>::Serve()
{
if(IsEmpty()) throw Underflow;
front=(front+1)%maxSize;
}
template<class T>
T SeqQueue<T>::Front()const
{
if(IsEmpty()) throw Underflow;
return q[(front+1)%maxSize];
}
template<class T>
void SeqQueue<T>::Output(ostream& out)const
{
out<<endl<<"the SeqQueue contains:";
for(int i=0;i<maxSize;i++)
{ rear=(rear+1)%maxSize;
out<<q[i];
}
out<<endl;
}
template<class T>
ostream &operator<<(ostream& out,const SeqQueue<T>& q)
{
q.Output(out);
return out;
}
void main()
{
try{
SeqQueue<int> a(10);
a.Append(1);
a.Append(2);
cout<<a;
}
catch(ResultCode err){
switch(err){
case Overflow:cout<<"Overflow!"<<endl;break;
case Underflow:cout<<"Underflow!"<<endl;break;
}
}