gpt4 book ai didi

c++ - 成对的 std::make_heap

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:36:07 29 4
gpt4 key购买 nike

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< (意思是:TU 提供 operator< ),我没有发现使用 make_heap 有任何问题。

关于c++ - 成对的 std::make_heap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4135834/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com