summaryrefslogtreecommitdiff
path: root/datastructures/stlPQ.cpp
diff options
context:
space:
mode:
authorPaul Jungeblut <paul.jungeblut@gmail.com>2018-05-21 22:11:51 +0200
committerGitHub <noreply@github.com>2018-05-21 22:11:51 +0200
commitadabbad9c51cf7cd3874bfde8eac1fbcf84fec10 (patch)
tree470d15c126cffc2f466dffb3dbeb949f39a55694 /datastructures/stlPQ.cpp
parentad25c63e9eb95cea1dab855bfc93ce7ec0754833 (diff)
parentb8dc20e2a9be3fc3053885a557c23bda8833a670 (diff)
Merge pull request #44 from TwoFX/stl_pq
Remove Skew Heaps and add STL PQs
Diffstat (limited to 'datastructures/stlPQ.cpp')
-rw-r--r--datastructures/stlPQ.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/datastructures/stlPQ.cpp b/datastructures/stlPQ.cpp
new file mode 100644
index 0000000..1de4abf
--- /dev/null
+++ b/datastructures/stlPQ.cpp
@@ -0,0 +1,14 @@
+#include <ext/pb_ds/priority_queue.hpp>
+template<typename T>
+using priorityQueue = __gnu_pbds::priority_queue<T, less<T>>; // greater<T> für Min-Queue
+
+int main() {
+ priorityQueue<int> pq;
+ auto it = pq.push(5); // O(1)
+ pq.push(7);
+ pq.pop(); // O(log n) amortisiert
+ pq.modify(it, 6); // O(log n) amortisiert
+ pq.erase(it); // O(log n) amortisiert
+ priorityQueue<int> pq2;
+ pq.join(pq2); // O(1)
+}