#include
const int MAXSIZE = 10;
template
class Myqueue
{
public:
Myqueue()
{
data = new TMAXSIZE;
real = front = 0;
}
~ Myqueue()
{
delete [] data;
}
bool Empty()
{
return real == front;
}
bool Full()
{
return (real + 1 + MAXSIZE) % MAXSIZE == front;
}
void Push(T val)
{
if(Full())
{
throw std::exception(“queue is Full!”);
}
data[real] = val;
real = (real + 1 + MAXSIZE) % MAXSIZE;
}
void Pop()
{
if(Empty())
{
throw std::exception(“queue is Empty!”);
}
front = (front + 1 + MAXSIZE) % MAXSIZE;
}
T top()
{
if(Empty())
{
throw std::exception(“queue is Empty!”);
}
T tmp = data[front];
front = (front + 1 + MAXSIZE) % MAXSIZE;
return tmp;
}
int Size()
{
return (real - front + MAXSIZE) % MAXSIZE;
}
void Show()
{
if(Empty())
{
return ;
}
std::cout<<“Queue::”<<std::endl;
for(int begin = front;begin != real;begin = (begin + 1 + MAXSIZE) % MAXSIZE)
{
std::cout<<data[begin]<<"-";
}
std::cout<<std::endl;
}
private:
T * data;
signed int real;
signed int front;
};
int main()
{
Myqueue que;
for(int i = 0;i <= 8;++i)
{
que.Push(i);
}
que.Show();
return 0;
}