#include<queue>
#include<iostream>
using namespace std;
class Pet{
private:
int type;
public:
Pet(){
}
Pet(int type){
this->type = type;
}
int getType(){
return type;
}
void setType(int i){
type =i;
}
};
class Cat:public Pet
{
};
class Dog:public Pet{
};
class Elem{
private:
Pet p;
int num;
public:
Elem(){}
Elem(Pet p, int num){
this->p = p;
this->num = num;
}
Pet getPet(){
return p;
}
void setPet(Pet p){
this->p = p;
}
void setNum(int num){
this->num = num;
}
int getNum(){
return num;
}
};
class CatDogQueue{
private:
queue<Elem> cat;
queue<Elem> dog;
public:
void push(Elem elem){
if(elem.getPet().getType() == 1){
cat.push(elem);
}else{
dog.push(elem);
}
}
Pet pollAll(){
Pet pet;
if(!cat.empty() && !dog.empty()){
if(cat.front().getNum() < dog.front().getNum()){
pet = cat.front().getPet();
cat.pop();
}else{
pet = dog.front().getPet();
dog.pop();
}
}else if(!cat.empty()){
pet = cat.front().getPet();
cat.pop();
}else if(!dog.empty()){
pet = dog.front().getPet();
dog.pop();
}
return pet;
}
Pet pollCat(){
if(!cat.empty()){
return cat.front().getPet();
}
}
bool isEmpty(){
if(cat.empty() && dog.empty()){
return true;
}else{
return false;
}
}
bool catIsEmpty(){
if(cat.empty())
return true;
return false;
}
bool dogIsEmpty(){
if(dog.empty())
return true;
return false;
}
};
int main(){
CatDogQueue cdq;
Cat c;
c.setType(1);
Elem e1;
e1.setPet(c);
e1.setNum(1);
Dog d;
d.setType(2);
Elem e2;
e2.setPet(d);
e2.setNum(2);
cdq.push(e1);
cdq.push(e2);
Pet p = cdq.pollAll();
cout << "pollall is :" << p.getType()<<endl;
p = cdq.pollAll();
cout << "pollall is :" << p.getType()<<endl;
if(cdq.isEmpty())
cout << "now,queue is empty "<<endl;
if(cdq.catIsEmpty())
cout << "now,cat queue is empty "<<endl;
if(cdq.dogIsEmpty())
cout << "now,dog queue is empty "<<endl;
Cat c2;
c2.setType(1);
Elem e3;
e3.setPet(c2);
e3.setNum(3);
cdq.push(e3);
cout << "cat enqueue " << endl;
if(!cdq.catIsEmpty()){
cout << "当猫队列有猫时,直接返回猫:" <<cdq.pollCat().getType() << endl;
}
return 0;
}