关于sort,priority_queue 的struct中自定义的排序方法会产生不同的序列
看例子:
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
struct Demo{
int x, y;
bool operator<(const Demo &A)const{
return x < A.x;
}
};
vector<Demo>D;
priority_queue<Demo>pq;
int main(){
for (int i = 0; i < 5; i++){
int X, Y; cin >> X >> Y;
Demo temp; temp.x = X, temp.y = Y;
D.push_back(temp);
pq.push(temp);
}
cout << "sort 函数的排列" << endl;
sort(D.begin(), D.end());
for (int i = 0; i < 5; i++){
cout << D[i].x << " " << D[i].y;
cout << endl;
}
cout << "priority_queue 输出序列" << endl;
while (!pq.empty()){
Demo temp = pq.top();
pq.pop();
cout << temp.x << " " << temp.y << endl;
}
system("pause");
}