我正在嘗試使用庫函數make_heap構建分堆。請在類比較中指出錯誤。根元素應該是數組中的最小元素,但它不是。構建最小堆
#include<iostream>
#include<map>
#include<algorithm>
using namespace std;
class compare {
bool operator()(pair<int, int> lhs,pair<int, int> rhs) const
{
return lhs.second < rhs.second;
}
};
int main()
{
int arr[]={9,2,5,7,3,5,7,5,4,5,6,4,5};
make_heap(arr,arr+13,compare);
cout<<arr[0];
}
什麼是 「它不工作」 是什麼意思?它做什麼,你期望它做什麼? –
*「這不起作用」*不是問題描述。除了得出結論說它可能只是懶得工作,你不會得到更多的實質性內容。 – IInspectable
我想建立一個使用lib fn max_heap的分鐘堆... plz建議某種方式。我迫切需要它。我是一個菜鳥。 – Anshul