src/work/bin_heap_demo.cc
changeset 80 629b9ca9184b
parent 37 e0e41f9e2be5
child 105 a3c73e9b9b2e
equal deleted inserted replaced
0:5a6df7255c14 1:0954c906224b
     6 using namespace marci;
     6 using namespace marci;
     7 using namespace std;
     7 using namespace std;
     8 
     8 
     9 class string_int_map;
     9 class string_int_map;
    10 
    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.
    11 typedef BinHeap<string, double, string_int_map> StrDoubleHeap;
    16 typedef BinHeap<string, double, string_int_map> StrDoubleHeap;
    12 
    17 
    13 class string_int_map : public map<string,int> {
    18 class string_int_map : public map<string,int> {
    14 public:
    19 public:
    15   int get(const string &s) {
    20   int get(const string &s) {
    76   cout << "heap.top() = "
    81   cout << "heap.top() = "
    77        << heap.top() << endl;
    82        << heap.top() << endl;
    78   cout << "heap.topValue() = "
    83   cout << "heap.topValue() = "
    79        << heap.topValue() << endl;
    84        << heap.topValue() << endl;
    80 
    85 
       
    86   cout << "heap.state(\"szilva\") = "
       
    87        << heap.state("szilva") << endl;
       
    88   cout << "heap.put(\"szilva\", 0.5);\n";
       
    89   heap.put("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 
    81   cout << "heap.size() = "
    99   cout << "heap.size() = "
    82        << heap.size() << endl;
   100        << heap.size() << endl;
    83   cout << "heap.pop();\n";
   101   cout << "heap.pop();\n";
    84   heap.pop();
   102   heap.pop();
    85 
   103 
    86   cout << "heap.size() = "
   104   cout << "heap.size() = "
    87        << heap.size() << endl;  
   105        << heap.size() << endl;  
    88   cout << "heap.empty() = "
   106   cout << "heap.empty() = "
    89        << (heap.empty()?"true":"false") << endl;  
   107        << (heap.empty()?"true":"false") << endl;  
    90 }
   108 }
    91