Ticket #9202: demo.cpp

File demo.cpp, 1.6 KB (added by André Grahl Pereira <andre.grahl.ai@…>, 9 years ago)
Line 
1#include <boost/heap/binomial_heap.hpp>
2#include <boost/heap/pairing_heap.hpp>
3#include <iostream>
4#include <cassert>
5#include <cstdlib>
6#include <string>
7
8struct Data
9{
10 unsigned int o;
11 unsigned int f;
12 Data(unsigned int iO, unsigned int iF) : o(iO), f(iF) {}
13};
14
15bool operator > (const Data& lhs, const Data& rhs){
16 return lhs.f > rhs.f;
17}
18
19std::ostream& operator << (std::ostream& o, const Data& data) {
20 return o << "Order: " << data.o << " F: " << data.f;
21}
22
23
24void case1() {
25 boost::heap::pairing_heap<Data, boost::heap::stable<true>, boost::heap::compare<std::greater<Data> > > openSet;
26
27 openSet.push(Data(1,0));
28 openSet.push(Data(2,0));
29
30 Data d = openSet.top();
31 std::cout << d << std::endl;
32 openSet.pop();
33
34 openSet.push(Data(3,0));
35
36 d = openSet.top();
37 std::cout << d << std::endl;
38 openSet.pop();
39
40 d = openSet.top();
41 std::cout << d << std::endl;
42 openSet.pop();
43}
44
45void case2() {
46 boost::heap::binomial_heap<Data, boost::heap::stable<true>, boost::heap::compare<std::greater<Data> > > openSet;
47
48 openSet.push(Data(1,0));
49 openSet.push(Data(2,0));
50
51 Data d = openSet.top();
52 std::cout << d << std::endl;
53 openSet.pop();
54
55 openSet.push(Data(3,0));
56
57 d = openSet.top();
58 std::cout << d << std::endl;
59 openSet.pop();
60
61 d = openSet.top();
62 std::cout << d << std::endl;
63 openSet.pop();
64}
65
66int main(int argc, char *argv[])
67{
68 std::cout << "pairing_heap:stable" << std::endl;
69 case1();
70
71 std::cout << "binomial_heap:stable" << std::endl;
72 case2();
73}
74