queue
#include<stdio.h>
#include<queue>
using namespace std;
int main() {
queue<int> qu;
qu.push(1);
qu.push(2);
qu.push(3);
printf("队列头 %d\n",qu.front());
printf("队列尾 %d\n",qu.back());
if(qu.empty()){
printf("No Empty");
}
qu.pop();
printf("长度%d",qu.size());
}
priority_queue
#include<stdio.h>
#include<queue>
#include<iostream>
using namespace std;
struct Fruit{
string name;
int price;
}f1,f2,f3;
struct cmp{
bool operator () (Fruit a,Fruit b){
return a.price > b.price;
}
};
int main() {
priority_queue<int> qu;
qu.push(4);
qu.push(1);
qu.push(2);
qu.push(3);
printf("队列头 %d\n",qu.top());
if(qu.empty()){
printf("No Empty");
}
qu.pop();
printf("长度%d\n",qu.size());
priority_queue<int,vector<int>,greater<int> >q;
q.push(4);
q.push(1);
q.push(2);
q.push(3);
printf("小级别队列头 %d\n",q.top());
priority_queue<Fruit,vector<Fruit>,cmp> fruitq;
f1.name = "桃子";
f1.price = 3;
f2.name = "梨子";
f2.price = 4;
f3.name = "苹果";
f3.price = 1;
fruitq.push(f1);
fruitq.push(f2);
fruitq.push(f3);
cout<<"队列头"<<fruitq.top().name<<fruitq.top().price<<endl;
}