没有优先队列的dijkstra不算真的dijkstra
所以我又回来补常识了
<1>priority_queue::emplace
<7>priority_queue::top
// priority_queue::emplace
#include
#include
#include
int main ()
{
std::priority_queue
mypq.emplace("orange");
mypq.emplace("strawberry");
mypq.emplace("apple");
mypq.emplace("pear");
std::cout << "mypq contains:";
while (!mypq.empty())
{
std::cout << ' ' << mypq.top();
mypq.pop();
}
std::cout << '\n';
return ;
}
//Ooutput:mypq contains: strawberry pear orange apple
<2>priority_queue::empty
<3>priority_queue::pop
<4>priority_queue::push
// priority_queue::push/pop
#include
#include
int main ()
{
std::priority_queue
mypq.push();
mypq.push();
mypq.push();
mypq.push();
std::cout << "Popping out elements…";
while (!mypq.empty())
{
std::cout << ' ' << mypq.top();
mypq.pop();
}
std::cout << '\n';
return ;
}
//Output:Popping out elements… 100 40 30 25
<5>priority_queue::size
<6>priority_queue::swap
// priority_queue::swap
#include
#include
int main ()
{
std::priority_queue
foo.push (); foo.push(); foo.push();
bar.push (); bar.push();
foo.swap(bar);
std::cout << "size of foo: " << foo.size() << '\n';
std::cout << "size of bar: " << bar.size() << '\n';
return ;
/*Output:
size of foo: 2
size of bar: 3*/
然后还有个自定义排序来着,到时候再摸。
手机扫一扫
移动阅读更方便
你可能感兴趣的文章