优先级队列作为最小堆c ++ vs python中的heapq如何将heapq.heappopopenList转换为c ++?

问题描述

我有以下python代码

    import heapq
    heapq.heappush(openList,currentSearchNode)
    #NOTE List of nodes that have been checked
    closedList = []
    while openList:
        #NOTE Pop the lowest fscore (to-go + been from or gscore + hscore) and set it as current
        currentSearchNode = heapq.heappop(openList)
...

我需要将其转换为C ++ 14,我尝试过:

#include <functional>
#include <queue>
priority_queue <Node,vector<Node>,greater<Node>> min_heap;
vector<Node> openList,closeList;
Node currentNode = Node(start,euclidean(start,end),0);
min_heap.emplace(openList,currentNode);
while (!openList.empty()) {
    currentNode = min_heap.pop(openList);
...
}

在Visual Studio中唯一显示为红色的问题是currentNode = min_heap.pop(openList);这行,正如您所看到的,它说的是pop的参数过多。正确的方法怎么做?

解决方法

怎么样,如下所示?

//TODO 1) require express,bodyparser & request
const express = require("express");
const bodyParser = require("body-parser");
const request = require("request");
//TODO 2) get the express
const app = express();

//TODO use bodyparser for getting the respnse from the local server
app.use(bodyParser.urlencoded({ extended: true }));
//TODO 3) specify the port for listening into the local server
app.listen(3000,function () {
    console.log("server is running at port 3000");
});
//TODO 4) sendFile - a file to the specific route
app.get("/",function (req,res) {
    res.sendFile(__dirname + "/index.html");
});
var theBitCoinPrice;
//TODO 5) post- use body parser for getting the response from the local server.

//TODO 6) request - use request function to use the API.
app.post("/",res) {
    console.log(req.body.fiat);//here we have log into the console thats why we are getting message in the console.
    // res.send("Your currency is " + req.body.fiat);
    var theFirstSymbol = req.body.crypto;
    var theSecondSymbol = req.body.fiat;
    var theAmount = req.body.amount;
    var options = {
        url: "https://apiv2.bitcoinaverage.com/convert/global",method: "GET",qs: {
            from: theFirstSymbol,to: theSecondSymbol,amount: theAmount,}
    }
    request(options,function (error,response,body) {
        var data = JSON.parse(body); //here we are converting JSON object into javascript object using parse method.
        var price = data.price;
        var date = data.time;
        console.log(date);
        response.write("<h1>" + "The current date is " + date + "</h1>");
        response.write("The " + theAmount + crypto + "is " + price + " " + fiat);
        response.send();
    });

});