#include<iostream>
#include<queue>
using namespace std;
int main() {
priority_queue<int>dui;
int n, t;
cout << "大爷您要输入几个数?" << endl;
cin >> n;
for (int i = 0; i < n;i++) {
cin >> t;
dui.push(t);
}
cout << "最大值:" << dui.top()<<endl;
cout << "不断输出较大值" << endl;
while (!dui.empty()) {
cout << dui.top() << " ";
dui.pop();
}
cout << "\n=========" << endl;
cout << "请再次输入" << n << "个数:" << endl;
priority_queue<int, vector<int>, greater<int>>dui2;
for (int i = 0; i < n; i++) {
cin >> t;
dui2.push(t);
}
cout << "最小值:" << dui2.top() << endl;
cout << "不断输出较小值" << endl;
while (!dui2.empty()) {
cout << dui2.top()<<" ";
dui2.pop();
}
system("pause");
return 0;
}
//队尾 <- 队首
//-1 1 2 3 4 less 逐渐减小(默认)
//10 8 7 6 5 greater 逐渐增大
|