COIN-OR::LEMON - Graph Library

source: lemon-0.x/src/work/bin_heap_demo.cc @ 176:f574ee5750fc

Last change on this file since 176:f574ee5750fc was 172:c645f4a2a6ae, checked in by Mihaly Barasz, 21 years ago

Uj kupac nevezektan

File size: 2.6 KB
Line 
1#include <iostream>
2#include <bin_heap.hh>
3#include <string>
4#include <map>
5
6using namespace hugo;
7using namespace std;
8
9class string_int_map;
10
11// Egy binaris kupac, ami stringekhez rendelt double ertekeket tarol,
12// azaz mindig az a string van a tetejen, amihez a legkisebb szam tartozik.
13// A kupac egy string_int_map tipusu property_map segitsegevel tarolja
14// a stringek aktualis helyet sajatmagan belul.
15// Egy olyan stringhez, ami meg nincsen a kupac -1 -et kell rendelnunk.
16typedef BinHeap<string, double, string_int_map> StrDoubleHeap;
17
18class string_int_map : public map<string,int> {
19public:
20  int get(const string &s) {
21    // Bocs, ez igy gaaaany, de nem volt kedvem utananezni, hogy
22    // hogy is mukodik ez a map :)
23    if( count(s) == 0 ) {
24      operator[](s) = StrDoubleHeap::PRE_HEAP;
25    }
26    return operator[](s);
27  }
28  void set(const string &s, int i) {
29      operator[](s) = i;
30  }
31};
32
33
34int main()
35{
36  string_int_map sim;
37 
38 
39  cout << "testing string_int_map default value:\n";
40  cout << "  alma: " << sim.get("alma") << endl;
41
42  cout << "creating the heap\n";
43  StrDoubleHeap heap(sim);
44
45  cout << "heap.push(\"alma\", 15);\n";
46  heap.push("alma", 15);
47
48  cout << "heap.set(\"korte\", 3.4);\n";
49  heap.set("korte", 3.4);
50
51  cout << "heap.get(\"alma\") = "
52       << heap.get("alma")
53       << endl;
54
55  cout << "heap.top() = "
56       << heap.top() << endl;
57  cout << "heap.topPrio() = "
58       << heap.topPrio() << endl;
59
60  cout << "heap.decrease(\"alma\", 1.2);\n";
61  heap.set("alma", 1.2);
62
63  cout << "heap.top() = "
64       << heap.top() << endl;
65  cout << "heap.topPrio() = "
66       << heap.topPrio() << endl;
67
68  cout << "heap.set(\"alma\", 22);\n";
69  heap.set("alma", 22);
70
71  cout << "heap.top() = "
72       << heap.top() << endl;
73  cout << "heap.topPrio() = "
74       << heap.topPrio() << endl;
75
76  cout << "heap.size() = "
77       << heap.size() << endl;
78  cout << "heap.pop();\n";
79  heap.pop();
80
81  cout << "heap.top() = "
82       << heap.top() << endl;
83  cout << "heap.topPrio() = "
84       << heap.topPrio() << endl;
85
86  cout << "heap.state(\"szilva\") = "
87       << heap.state("szilva") << endl;
88  cout << "heap.set(\"szilva\", 0.5);\n";
89  heap.set("szilva", 0.5);
90  cout << "heap.state(\"szilva\") = "
91       << heap.state("szilva") << endl;
92  cout << "heap.top() = "
93       << heap.top() << endl;
94  cout << "heap.pop();\n";
95  heap.pop();
96  cout << "heap.state(\"szilva\") = "
97       << heap.state("szilva") << endl;
98
99  cout << "heap.size() = "
100       << heap.size() << endl;
101  cout << "heap.pop();\n";
102  heap.pop();
103
104  cout << "heap.size() = "
105       << heap.size() << endl; 
106  cout << "heap.empty() = "
107       << (heap.empty()?"true":"false") << endl; 
108}
Note: See TracBrowser for help on using the repository browser.