1 #include<iostream> 2 #include<queue> 3 #include<vector> 4 using namespace std; 5 6 struct cmp { 7 bool operator ()(int &a, int &b) { 8 return a > b;//从小到大 9 } 10 }; 11 12 int main(){ 13 int a[] = { 14,10,56,7,83,22,36,91,3,47 }; 14 priority_queue<int>que; 15 priority_queue<int, vector<int>, cmp>que1; 16 17 for (int i = 0; i < 10; i++) { 18 que.push(a[i]); 19 que1.push(a[i]); 20 } 21 22 while (!que.empty()) { 23 cout << que.top() << " "; 24 que.pop(); 25 } 26 27 cout << endl; 28 while (!que1.empty()) { 29 cout << que1.top() << " "; 30 que1.pop(); 31 } 32 33 system("pause"); 34 return 0; 35 }