Is it possible to do make_heap() with a pair in a vector?
I'm using:
std::vector< std::pair < int , tablero& > > lista_abierta_;
I use the object function to order the pair by the first member, but it crashes.
The code is:
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include "8_puzzle.h"
#include "tablero.h"
using namespace std;
class comp {
public:
bool operator()(pair < int, tablero&> a, pair < int, tablero&> b) const {
return a.first > b.first;
}
};
pair < int, tablero& > puzzle::A_estrella::tope()
{
pair < int, tablero& > l=lista_abierta_.front();
pop_heap(lista_abierta_.begin(),lista_abierta_.end());
lista_abierta_.pop_back();
return l;
}
[Taken from here]
As long as std::pair<T, U> provides operator< (meaning : T and U provide operator<), I don't see any issue in using make_heap.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With