#include <iostream>
#include <queue>
using namespace std;
void make_copy(priority_queue<int, vector<int>> pq, vector<int> &arr)
{
arr = {}; // if it was not empty , make it :)
while (!pq.empty())
{
arr.push_back(pq.top());
pq.pop();
}
}
int main()
{
priority_queue<int, vector<int>> q;
q.push(1);
q.push(2);
q.push(3);
vector<int> arr;
make_copy(q, arr); // this will copy all elements of q to arr :)
for (auto &x : arr)
{
cout << x << " ";
}
}
制作副本并对其进行迭代 - 由@lie-ryan 建议