src/work/bin_heap_demo.cc
changeset 196 8a9b9360463e
parent 105 a3c73e9b9b2e
child 214 44f01e580f16
equal deleted inserted replaced
2:afdc35e85b4a 3:79ae9c125881
    23     if( count(s) == 0 ) {
    23     if( count(s) == 0 ) {
    24       operator[](s) = StrDoubleHeap::PRE_HEAP;
    24       operator[](s) = StrDoubleHeap::PRE_HEAP;
    25     }
    25     }
    26     return operator[](s);
    26     return operator[](s);
    27   }
    27   }
    28   void put(const string &s, int i) {
    28   void set(const string &s, int i) {
    29       operator[](s) = i;
    29       operator[](s) = i;
    30   }
    30   }
    31 };
    31 };
    32 
    32 
    33 
    33 
    43   StrDoubleHeap heap(sim);
    43   StrDoubleHeap heap(sim);
    44 
    44 
    45   cout << "heap.push(\"alma\", 15);\n";
    45   cout << "heap.push(\"alma\", 15);\n";
    46   heap.push("alma", 15);
    46   heap.push("alma", 15);
    47 
    47 
    48   cout << "heap.put(\"korte\", 3.4);\n";
    48   cout << "heap.set(\"korte\", 3.4);\n";
    49   heap.put("korte", 3.4);
    49   heap.set("korte", 3.4);
    50 
    50 
    51   cout << "heap.get(\"alma\") = " 
    51   cout << "heap.get(\"alma\") = " 
    52        << heap.get("alma")
    52        << heap.get("alma")
    53        << endl;
    53        << endl;
    54 
    54 
    55   cout << "heap.top() = "
    55   cout << "heap.top() = "
    56        << heap.top() << endl;
    56        << heap.top() << endl;
    57   cout << "heap.topValue() = "
    57   cout << "heap.topPrio() = "
    58        << heap.topValue() << endl;
    58        << heap.topPrio() << endl;
    59 
    59 
    60   cout << "heap.decrease(\"alma\", 1.2);\n";
    60   cout << "heap.decrease(\"alma\", 1.2);\n";
    61   heap.put("alma", 1.2);
    61   heap.set("alma", 1.2);
    62 
    62 
    63   cout << "heap.top() = "
    63   cout << "heap.top() = "
    64        << heap.top() << endl;
    64        << heap.top() << endl;
    65   cout << "heap.topValue() = "
    65   cout << "heap.topPrio() = "
    66        << heap.topValue() << endl;
    66        << heap.topPrio() << endl;
    67 
    67 
    68   cout << "heap.put(\"alma\", 22);\n";
    68   cout << "heap.set(\"alma\", 22);\n";
    69   heap.put("alma", 22);
    69   heap.set("alma", 22);
    70 
    70 
    71   cout << "heap.top() = "
    71   cout << "heap.top() = "
    72        << heap.top() << endl;
    72        << heap.top() << endl;
    73   cout << "heap.topValue() = "
    73   cout << "heap.topPrio() = "
    74        << heap.topValue() << endl;
    74        << heap.topPrio() << endl;
    75 
    75 
    76   cout << "heap.size() = "
    76   cout << "heap.size() = "
    77        << heap.size() << endl;
    77        << heap.size() << endl;
    78   cout << "heap.pop();\n";
    78   cout << "heap.pop();\n";
    79   heap.pop();
    79   heap.pop();
    80 
    80 
    81   cout << "heap.top() = "
    81   cout << "heap.top() = "
    82        << heap.top() << endl;
    82        << heap.top() << endl;
    83   cout << "heap.topValue() = "
    83   cout << "heap.topPrio() = "
    84        << heap.topValue() << endl;
    84        << heap.topPrio() << endl;
    85 
    85 
    86   cout << "heap.state(\"szilva\") = "
    86   cout << "heap.state(\"szilva\") = "
    87        << heap.state("szilva") << endl;
    87        << heap.state("szilva") << endl;
    88   cout << "heap.put(\"szilva\", 0.5);\n";
    88   cout << "heap.set(\"szilva\", 0.5);\n";
    89   heap.put("szilva", 0.5);
    89   heap.set("szilva", 0.5);
    90   cout << "heap.state(\"szilva\") = "
    90   cout << "heap.state(\"szilva\") = "
    91        << heap.state("szilva") << endl;
    91        << heap.state("szilva") << endl;
    92   cout << "heap.top() = "
    92   cout << "heap.top() = "
    93        << heap.top() << endl;
    93        << heap.top() << endl;
    94   cout << "heap.pop();\n";
    94   cout << "heap.pop();\n";