#include<iostream>
#include<string.h>
#include<stdlib.h>
using namespace std;
const int capacity=10;
template<class T>
class Queue
{
public:
Queue()
{
data=new T [capacity];
front=rear=num=0;
}
~Queue()
{
delete [] data;
}
void push(T a)
{
if(isfull()){cout<<"full"<<endl;}
else
{
front=(front+1)%capacity;
num++;
data[front]=a;
}
}
T pop()
{
if(isempty()){cout<<"empty";}
else
{
rear=(rear+1)%capacity;
num--;
cout<<data[rear]<<endl;
}
}
bool isempty()
{
return num==0;
}
bool isfull()
{
return num==capacity;
}
private:
int front,rear,num;
T *data;
};
int main()
{
Queue<int> p[3];
p[0].push(3);
p[1].push(4);
p[2].push(6);
Queue<char> q[3];
q[0].push('s');
q[1].push('d');
q[2].push('f');
p[0].pop();
q[0].pop();
p[1].pop();
q[1].pop();
p[2].pop();
q[2].pop();
return 0;
}
#include<string.h>
#include<stdlib.h>
using namespace std;
const int capacity=10;
template<class T>
class Queue
{
public:
Queue()
{
data=new T [capacity];
front=rear=num=0;
}
~Queue()
{
delete [] data;
}
void push(T a)
{
if(isfull()){cout<<"full"<<endl;}
else
{
front=(front+1)%capacity;
num++;
data[front]=a;
}
}
T pop()
{
if(isempty()){cout<<"empty";}
else
{
rear=(rear+1)%capacity;
num--;
cout<<data[rear]<<endl;
}
}
bool isempty()
{
return num==0;
}
bool isfull()
{
return num==capacity;
}
private:
int front,rear,num;
T *data;
};
int main()
{
Queue<int> p[3];
p[0].push(3);
p[1].push(4);
p[2].push(6);
Queue<char> q[3];
q[0].push('s');
q[1].push('d');
q[2].push('f');
p[0].pop();
q[0].pop();
p[1].pop();
q[1].pop();
p[2].pop();
q[2].pop();
return 0;
}