|
@@ -0,0 +1,54 @@
|
|
|
+#include <iostream>
|
|
|
+#include <queue> // priority_queue
|
|
|
+#include <utility> // pair
|
|
|
+#include <functional> // greater
|
|
|
+#include <limits>
|
|
|
+
|
|
|
+using namespace std;
|
|
|
+
|
|
|
+int main() {
|
|
|
+ cout << "Hello containers !" << endl;
|
|
|
+
|
|
|
+ cout << "# Priority queue" << endl;
|
|
|
+ cout << "## With integers" << endl;
|
|
|
+
|
|
|
+ priority_queue<int> pqInt;
|
|
|
+
|
|
|
+ pqInt.push(5);
|
|
|
+ pqInt.push(2);
|
|
|
+ pqInt.push(0);
|
|
|
+ pqInt.push(42);
|
|
|
+ pqInt.push(3);
|
|
|
+ pqInt.push(numeric_limits<int>::max());
|
|
|
+
|
|
|
+ while (!pqInt.empty()) {
|
|
|
+ cout << pqInt.top() << " > ";
|
|
|
+ pqInt.pop();
|
|
|
+ }
|
|
|
+ cout << endl;
|
|
|
+
|
|
|
+ cout << "## With pairs" << endl;
|
|
|
+
|
|
|
+ priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pqPair;
|
|
|
+
|
|
|
+ pqPair.push(make_pair(4, 4));
|
|
|
+ pqPair.push(make_pair(4, 5));
|
|
|
+ pqPair.push(make_pair(5, 5));
|
|
|
+ pqPair.push(make_pair(2, 5));
|
|
|
+ pqPair.push(make_pair(0, 5));
|
|
|
+ pqPair.push(make_pair(42, 5));
|
|
|
+ pqPair.push(make_pair(3, 5));
|
|
|
+ pqPair.push(make_pair(3, 5));
|
|
|
+ pqPair.push(make_pair(3, 2));
|
|
|
+ pqPair.push(make_pair(3, 0));
|
|
|
+ pqPair.push(make_pair(3, 42));
|
|
|
+ pqPair.push(make_pair(3, 3));
|
|
|
+
|
|
|
+ while (!pqPair.empty()) {
|
|
|
+ cout << pqPair.top().first << ';' << pqPair.top().second << " > ";
|
|
|
+ pqPair.pop();
|
|
|
+ }
|
|
|
+ cout << endl;
|
|
|
+
|
|
|
+ return 0;
|
|
|
+}
|