#ifndef PRIORITY_QUEUE
#define PRIORITY_QUEUE
struct node
{
int x,y;
friend bool operator>( const node &a, const node &b)
{
return a.x<b.x;
}
};
void default_sort();
void uporder();
void user_defined();
void PRIORITY_test();
#endif
#include "priority_queue.h"
#include<iostream>
#include<queue>
using namespace std;
void default_sort()
{
cout<<"default_sort"<<endl;
priority_queue<int>q1;
int n = 6;
for(int i = 0;i<n;i++)
{
q1.push(i+1);
}
while(!q1.empty())
{
cout<<q1.top()<<endl;
q1.pop();
}
}
void uporder()
{
cout<<"uporder"<<endl;
priority_queue<int,vector<int>,greater<int> >q1;
int n = 6;
for(int i = 0;i<n;i++)
{
q1.push(9-i);
}
while(!q1.empty())
{
cout<<q1.top()<<endl;
q1.pop();
}
}
void user_defined()
{
cout<<"user_defined_up"<<endl;
struct cmp1
{
bool operator()(int x,int y)
{
return x>y;
}
};
priority_queue<int,vector<int>,cmp1>q1;
int n = 6;
for(int i = 0;i<n;i++)
{
q1.push(9-i);
}
while(!q1.empty())
{
cout<<q1.top()<<endl;
q1.pop();
}
cout<<"user_defined_suzhu"<<endl;
struct cmp2
{
int tmp[100];
bool operator()(const int x,const int y)
{
return tmp[x]>tmp[y];
}
};
priority_queue<int,vector<int>,cmp2>q2;
for(int i = 0;i<n;i++)
{
q2.push(9-i);
}
while(!q2.empty())
{
cout<<q2.top()<<endl;
q2.pop();
}
cout<<"user_defined_struct"<<endl;
priority_queue<node>q4;
node a;
for(int i = 0;i<n;i++)
{
a.x = 9-i;
a.y = i+2;
q4.push(a);
}
while(!q4.empty())
{
cout<<q4.top().x<<q4.top().y<<endl;
q4.pop();
}
}
void PRIORITY_test()
{
default_sort();
uporder();
user_defined();
}
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/7ff8c6bf75d278cccccf52d5051efbbf.png)