循环队列
#include <iostream>
using namespace std;
template <typename T>
class Queue
{
private:
int front;
int rear;
T data;
int MAXSIZE;
T *p;
public:
Queue(){
cout<<"无参构造"<<endl;};
Queue(int m,T size):MAXSIZE(m),p(new T (sizeof (size))){
front=0;
rear=0;
cout<<"有参构造函数"<<endl;
}
~Queue(){
delete p;
cout<<"析构函数"<<endl;
}
Queue(const Queue &other){
int size=(other.rear-other.front+MAXSIZE)%MAXSIZE;
T *q=p;
memcpy(p,other.p,sizeof(T)*size);
delete q;
q=nullptr;
cout<<"拷贝构造"<<endl;
}
Queue&operator=(const Queue &other){
int size=(other.rear-other.front+MAXSIZE)%MAXSIZE;
T *q=p;
memcpy(p,other.p,sizeof(T)*size);
delete q;
q=nullptr;
cout<<"拷贝赋值"<<endl;
return *this;
}
bool empty()
{
if(this->front==this->rear){
return true;
}
else{
return false;
}