私はダイクストラのアルゴリズムを実装しており、STLの「priority_queue」を使用してコーディングプロセスを高速化したいのですが、C ++でコーディングしようとする試みではよくあることですが、言語を理解していないために速度が低下しています。この例はhttp://www.cplusplus.com/reference/stl/priority_queue/priority_queue/で見つかりましたが、次のことを理解していません。
// constructing priority queues
#include <iostream>
#include <queue>
using namespace std;
class mycomparison
{
bool reverse;
public:
mycomparison(const bool& revparam=false)
{reverse=revparam;}
bool operator() (const int& lhs, const int&rhs) const
{
if (reverse) return (lhs>rhs);
else return (lhs<rhs);
}
};
int main ()
{
int myints[]= {10,60,50,20};
priority_queue<int> first;
priority_queue<int> second (myints,myints+4);
priority_queue< int, vector<int>, greater<int> > third (myints,myints+4);
// using mycomparison:
priority_queue< int, vector<int>, mycomparison > fourth;
typedef priority_queue<int,vector<int>,mycomparison> mypq_type;
mypq_type fifth (mycomparison());
mypq_type sixth (mycomparison(true));
return 0;
}
具体的には、「bool operator()(const int&lhs、const int&rhs)const」が私をつまずかせています。残りは大丈夫です。演算子のオーバーロードだと思いますが、「operator()」は私には意味がありません。どんな助けでもいただければ幸いです。