src/work/bin_heap_demo.cc
changeset 1365 c280de819a73
parent 1364 ee5959aa4410
child 1366 d00b85f8be45
     1.1 --- a/src/work/bin_heap_demo.cc	Sun Apr 17 18:57:22 2005 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,114 +0,0 @@
     1.4 -#include <iostream>
     1.5 -#include <string>
     1.6 -#include <map>
     1.7 -
     1.8 -#include <lemon/bin_heap.h>
     1.9 -
    1.10 -using namespace lemon;
    1.11 -using namespace std;
    1.12 -
    1.13 -class string_int_map;
    1.14 -
    1.15 -// Egy binaris kupac, ami stringekhez rendelt double ertekeket tarol,
    1.16 -// azaz mindig az a string van a tetejen, amihez a legkisebb szam tartozik.
    1.17 -// A kupac egy string_int_map tipusu property_map segitsegevel tarolja
    1.18 -// a stringek aktualis helyet sajatmagan belul.
    1.19 -// Egy olyan stringhez, ami meg nincsen a kupac -1 -et kell rendelnunk.
    1.20 -typedef BinHeap<string, double, string_int_map> StrDoubleHeap;
    1.21 -
    1.22 -class string_int_map : public map<string,int> {
    1.23 -  typedef map<string,int> parent;
    1.24 -public:
    1.25 -  int get(const string &s) {
    1.26 -    // Bocs, ez igy gaaaany, de nem volt kedvem utananezni, hogy
    1.27 -    // hogy is mukodik ez a map :)
    1.28 -    if( count(s) == 0 ) {
    1.29 -      parent::operator[](s) = StrDoubleHeap::PRE_HEAP;
    1.30 -    }
    1.31 -    return parent::operator[](s);
    1.32 -  }
    1.33 -  int operator[](const string &s) {
    1.34 -    return get(s);
    1.35 -  }
    1.36 -  void set(const string &s, int i) {
    1.37 -      parent::operator[](s) = i;
    1.38 -  }
    1.39 -};
    1.40 -
    1.41 -
    1.42 -int main()
    1.43 -{
    1.44 -  string_int_map sim;
    1.45 -  
    1.46 -  
    1.47 -  cout << "testing string_int_map default value:\n";
    1.48 -  cout << "  sim.get(\"alma\"): " << sim.get("alma") << endl;
    1.49 -  cout << "  sim[\"alma\"]: " << sim["alma"] << endl;
    1.50 -
    1.51 -  cout << "creating the heap\n";
    1.52 -  StrDoubleHeap heap(sim);
    1.53 -
    1.54 -  cout << "heap.push(\"alma\", 15);\n";
    1.55 -  heap.push("alma", 15);
    1.56 -
    1.57 -  cout << "heap.set(\"korte\", 3.4);\n";
    1.58 -  heap.set("korte", 3.4);
    1.59 -
    1.60 -  cout << "heap[\"alma\"] = " 
    1.61 -       << heap["alma"]
    1.62 -       << endl;
    1.63 -
    1.64 -  cout << "heap.top() = "
    1.65 -       << heap.top() << endl;
    1.66 -  cout << "heap.prio() = "
    1.67 -       << heap.prio() << endl;
    1.68 -
    1.69 -  cout << "heap.decrease(\"alma\", 1.2);\n";
    1.70 -  heap.set("alma", 1.2);
    1.71 -
    1.72 -  cout << "heap.top() = "
    1.73 -       << heap.top() << endl;
    1.74 -  cout << "heap.prio() = "
    1.75 -       << heap.prio() << endl;
    1.76 -
    1.77 -  cout << "heap.set(\"alma\", 22);\n";
    1.78 -  heap.set("alma", 22);
    1.79 -
    1.80 -  cout << "heap.top() = "
    1.81 -       << heap.top() << endl;
    1.82 -  cout << "heap.prio() = "
    1.83 -       << heap.prio() << endl;
    1.84 -
    1.85 -  cout << "heap.size() = "
    1.86 -       << heap.size() << endl;
    1.87 -  cout << "heap.pop();\n";
    1.88 -  heap.pop();
    1.89 -
    1.90 -  cout << "heap.top() = "
    1.91 -       << heap.top() << endl;
    1.92 -  cout << "heap.prio() = "
    1.93 -       << heap.prio() << endl;
    1.94 -
    1.95 -  cout << "heap.state(\"szilva\") = "
    1.96 -       << heap.state("szilva") << endl;
    1.97 -  cout << "heap.set(\"szilva\", 0.5);\n";
    1.98 -  heap.set("szilva", 0.5);
    1.99 -  cout << "heap.state(\"szilva\") = "
   1.100 -       << heap.state("szilva") << endl;
   1.101 -  cout << "heap.top() = "
   1.102 -       << heap.top() << endl;
   1.103 -  cout << "heap.pop();\n";
   1.104 -  heap.pop();
   1.105 -  cout << "heap.state(\"szilva\") = "
   1.106 -       << heap.state("szilva") << endl;
   1.107 -
   1.108 -  cout << "heap.size() = "
   1.109 -       << heap.size() << endl;
   1.110 -  cout << "heap.pop();\n";
   1.111 -  heap.pop();
   1.112 -
   1.113 -  cout << "heap.size() = "
   1.114 -       << heap.size() << endl;  
   1.115 -  cout << "heap.empty() = "
   1.116 -       << (heap.empty()?"true":"false") << endl;  
   1.117 -}