home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / leda / incl / k_heap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  2.0 KB  |  108 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  k_heap.h
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16.  
  17. #ifndef KHEAP_H
  18. #define KHEAP_H
  19.  
  20. //------------------------------------------------------------------------------
  21. //
  22. // K-nary Heaps
  23. //
  24. // S. Naeher 1990
  25. //
  26. //------------------------------------------------------------------------------
  27.  
  28.  
  29. #include <LEDA/basic.h>
  30. #include <LEDA/slist.h>
  31.  
  32.  
  33. typedef int k_heap_item;
  34.  
  35.  
  36. class K_HEAP  {
  37.  
  38. virtual int  cmp(ent& x, ent& y){ return int(x)-int(y); }
  39. virtual void print_key(ent& x)  { Print(x); }
  40. virtual void print_inf(ent& x)  { Print(x); }
  41.  
  42. int  K;
  43. ent* Key;
  44. ent* Inf;
  45. int* Pos;
  46. int* Item;
  47.  
  48. SLIST free_items;
  49.  
  50. int count;
  51. int max_count;
  52.  
  53. void rise(int&,ent,ent);
  54. void sink(int&,ent,ent);
  55.  
  56.  
  57. public:
  58.  
  59.  K_HEAP(int,int=2);
  60. ~K_HEAP();
  61.  
  62. int insert(ent k, ent i);
  63. int insert0(ent k, ent i);
  64.  
  65. void decrease_inf(k_heap_item, ent);
  66.  
  67. void change_key(k_heap_item it, ent k) { Key[Pos[it]] = k; }
  68.  
  69. ent del_item(k_heap_item);
  70.  
  71. ent del_min()   { return del_item(Item[0]); }
  72.  
  73. ent  key(int it) const { return Key[Pos[it]]; }
  74. ent  inf(int it) const { return Inf[Pos[it]]; }
  75.  
  76. k_heap_item  find_min()  const { return (count>0) ? Item[0] : 0;  }
  77.  
  78. int  size()    const   { return count;    }
  79. bool empty()   const  { return count==0; }
  80. void clear();
  81.  
  82. void print();
  83.  
  84. };
  85.  
  86. class k_heap : public K_HEAP {
  87.  
  88. virtual int  cmp(ent& x, ent& y){ return int(x)-int(y); }
  89. virtual void print_key(ent& x)  { Print(x); }
  90. virtual void print_inf(ent& x)  { Print(x); }
  91.  
  92. public:
  93.  
  94.  k_heap(int N,int k=2) : K_HEAP(N,k) {};
  95. ~k_heap() {};
  96.  
  97. k_heap_item insert(ent k, int i) { return K_HEAP::insert(k,Ent(i)); };
  98.  
  99. void decrease_inf(k_heap_item it, int x) { K_HEAP::decrease_inf(it,Ent(x)); };
  100.  
  101. int  inf(k_heap_item it) const { return (int)K_HEAP::key(it); }
  102.  
  103. };
  104.  
  105.  
  106. #endif
  107.