#include <cstdio>
#include <cstring>
#include <iostream>
#include <functional>
#include <queue>
using namespace std;
int ar[13] = {14,10,56,7,83,22,36,91,3,47,72,0};
struct cmp1
{
bool operator ()(int &a,int &b)
{
return a > b;//以后面的b为准a》b所以小的先出来
}
};
struct cmp2
{
bool operator ()(int &a,int &b)
{
return a < b;
}
};
struct node1
{
int x;
bool operator < (const node1 &a) const
{
return x > a.x;
}
};
struct node2
{
int x;
bool operator < (const node2 &a) const//注意每一个const
{
return x < a.x;
}
};
node1 num1[13];
node2 num2[13];
int main()
{
int i;
priority_queue<int>q;
priority_queue<int,vector<int>,cmp1>q1;
priority_queue<int,vector<int>,cmp2>q2;
priority_queue<int,vector<int>,greater<int> >q3;//注意空格
priority_queue<int,vector<int>,less<int> >q4;
priority_queue<node1>q5;
priority_queue<node2>q6;
for (i = 0; i < 12; ++i)
{
num1[i].x = num2[i].x = ar[i];
}
for (i = 0; i < 12; ++i)
{
q.push(ar[i]);
q1.push(ar[i]);
q2.push(ar[i]);
q3.push(ar[i]);
q4.push(ar[i]);
}
for (i = 0; i < 12; ++i)
{
q5.push(num1[i]);
q6.push(num2[i]);
}
printf("采用系统默认方式:\n");
while (!q.empty())
{
printf("%d ",q.top());
q.pop();
}
printf("\n");
printf("***********************\n");
printf("采用自定义优先级反方式\n");
while (!q1.empty())
{
printf("%d ",q1.top());
q1.pop();
}
printf("\n");
printf("***********************\n");
while (!q2.empty())
{
printf("%d ",q2.top());
q2.pop();
}
printf("\n");
printf("***********************\n");
printf("采用functional头文件方式\n");
while (!q3.empty())
{
printf("%d ",q3.top());
q3.pop();
}
printf("\n");
printf("***********************\n");
while (!q4.empty())
{
printf("%d ",q4.top());
q4.pop();
}
printf("\n");
printf("***********************\n");
printf("采用定义结构体中优先级的方式\n");
while (!q5.empty())
{
node1 t = q5.top();
printf("%d ",t.x);
q5.pop();
}
printf("\n");
printf("***********************\n");
while (!q6.empty())
{
node2 t = q6.top();
printf("%d ",t.x);
q6.pop();
}
printf("\n");
printf("***********************\n");
return 0;
}