我是 C++ 的初学者。我正在尝试使用 std::priority_queue 创建一个 maxheap 和一个 minheap。只创建一个 maxheap 可以正常工作,但不能同时创建。我似乎无法理解错误。我收到以下错误:无法将 'minHeap' 从 'std::priority_queue, compare>' 转换为 'std::priority_queue' 尝试搜索互联网但无济于事。下面是代码。
void addNum(int num, priority_queue<int> maxHeap, priority_queue<int> minHeap) {
if (minHeap.size() == 0 || num > minHeap.top())
minHeap.push(num);
else if (num < minHeap.top())
maxHeap.push(num);
}
void createHeaps(vector<int> a) {
priority_queue<int> maxHeap;
priority_queue<int, vector<int>, greater<int> > minHeap;
for (int i = 0; i < a.size(); ++i) {
int num = a[i];
addNum(num, maxHeap, minHeap);
}
}