I was just experimenting with make_heap() function in C++. Following is the code where I am keeping a track of the elements that are being compared every time the bool predicate() is called, by printing them.
#include <iostream>
#include <algorithm>
using namespace std;
// bool predicate function to make a min heap
bool predicate(int a, int b){
cout << a << " " << b << endl;
if(a >= b){ return 1; }
return 0;
}
int main(){
int arr[] = {3,2,1,-1,-2};
make_heap(arr, arr+5, predicate);
return 0;
}
The output that I am getting is :
-2 -1
-2 2
1 -2
2 -1
-1 3
But I was expecting the following output, keeping in view the standard algorithm :
-2 -1
-2 2
1 -2
3 -2
2 -1
-1 3
any help ?