没有优先队列的dijkstra不算真的dijkstra
所以我又回来补常识了
<1>priority_queue::emplace
<7>priority_queue::top
1 // priority_queue::emplace 2 #include <iostream> // std::cout 3 #include <queue> // std::priority_queue 4 #include <string> // std::string 5 6 int main () 7 { 8 std::priority_queue<std::string> mypq; 9 10 mypq.emplace("orange"); 11 mypq.emplace("strawberry"); 12 mypq.emplace("apple"); 13 mypq.emplace("pear"); 14 15 std::cout << "mypq contains:"; 16 while (!mypq.empty()) 17 { 18 std::cout << ' ' << mypq.top(); 19 mypq.pop(); 20 } 21 std::cout << '\n'; 22 23 return 0; 24 } 25 //Ooutput:mypq contains: strawberry pear orange apple
<2>priority_queue::empty
<3>priority_queue::pop
<4>priority_queue::push
1 // priority_queue::push/pop 2 #include <iostream> // std::cout 3 #include <queue> // std::priority_queue 4 5 int main () 6 { 7 std::priority_queue<int> mypq; 8 9 mypq.push(30); 10 mypq.push(100); 11 mypq.push(25); 12 mypq.push(40); 13 14 std::cout << "Popping out elements..."; 15 while (!mypq.empty()) 16 { 17 std::cout << ' ' << mypq.top(); 18 mypq.pop(); 19 } 20 std::cout << '\n'; 21 22 return 0; 23 } 24 //Output:Popping out elements... 100 40 30 25
<5>priority_queue::size
<6>priority_queue::swap
1 // priority_queue::swap 2 #include <iostream> // std::cout 3 #include <queue> // std::priority_queue 4 5 int main () 6 { 7 std::priority_queue<int> foo,bar; 8 foo.push (15); foo.push(30); foo.push(10); 9 bar.push (101); bar.push(202); 10 11 foo.swap(bar); 12 13 std::cout << "size of foo: " << foo.size() << '\n'; 14 std::cout << "size of bar: " << bar.size() << '\n'; 15 16 return 0; 17 18 /*Output: 19 size of foo: 2 20 size of bar: 3*/
然后还有个自定义排序来着,到时候再摸。