make_heap()
可以用 vector 中的一对来实现吗?
我正在使用:
std::vector< std::pair < int , tablero& > > lista_abierta_;
我使用对象函数按第一个成员对对排序,但它崩溃了。
代码是:
#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;
}
[取自here ]
最佳答案
只要std::pair<T, U>
提供 operator<
(意思是:T
和 U
提供 operator<
),我没有发现使用 make_heap 有任何问题。
关于c++ - 成对的 std::make_heap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4135834/