| 1 | #include <cstdlib>
|
|---|
| 2 | #include "boost/heap/binomial_heap.hpp"
|
|---|
| 3 |
|
|---|
| 4 | using namespace std;
|
|---|
| 5 |
|
|---|
| 6 | int main(int argc, char** argv) {
|
|---|
| 7 |
|
|---|
| 8 | typedef typename boost::heap::binomial_heap<int, boost::heap::mutable_<true>> Heap;
|
|---|
| 9 | typedef Heap::handle_type handle_t;
|
|---|
| 10 |
|
|---|
| 11 | Heap heap;
|
|---|
| 12 |
|
|---|
| 13 | handle_t t3 = heap.push(1);
|
|---|
| 14 | handle_t t5 = heap.push(2);
|
|---|
| 15 | handle_t t1 = heap.push(3);
|
|---|
| 16 |
|
|---|
| 17 | *t3 = 4;
|
|---|
| 18 | heap.update(t3);
|
|---|
| 19 |
|
|---|
| 20 | *t5 = 1;
|
|---|
| 21 | heap.update(t5);
|
|---|
| 22 |
|
|---|
| 23 | *t1 = 7;
|
|---|
| 24 | heap.update(t1);
|
|---|
| 25 |
|
|---|
| 26 | cout << "Priority Queue: update with fixup" << endl;
|
|---|
| 27 | while (!heap.empty()) {
|
|---|
| 28 | cout << heap.top() << " "; //result: 4, 7, 1 correct: 7 4 1
|
|---|
| 29 | heap.pop();
|
|---|
| 30 | }
|
|---|
| 31 | cout << endl;
|
|---|
| 32 | }
|
|---|