b_prio.h
上传用户:gzelex
上传日期:2007-01-07
资源大小:707k
文件大小:2k
开发平台:

MultiPlatform

  1. /*******************************************************************************
  2. +
  3. +  LEDA-R  3.2.3
  4. +
  5. +  b_prio.h
  6. +
  7. +  Copyright (c) 1995  by  Max-Planck-Institut fuer Informatik
  8. +  Im Stadtwald, 66123 Saarbruecken, Germany     
  9. +  All rights reserved.
  10. *******************************************************************************/
  11. #ifndef LEDA_BPRIO_H
  12. #define LEDA_BPRIO_H
  13. //------------------------------------------------------------------------------
  14. // b_priority_queues: bounded priority queues implemented by b_heaps 
  15. //------------------------------------------------------------------------------
  16. #include <LEDA/impl/b_heap.h>
  17. /*{Manpage {b_priority_queue} {K} {Bounded Priority Queues}}*/
  18. typedef b_heap_item b_pq_item;
  19. template<class K> 
  20. class b_priority_queue : public b_heap 
  21. {
  22. /*{Mdefinition 
  23. An instance $Q$ of the parameterized data type name is a
  24. priority_queue (cf. section ref{Priority Queues}) whose information type is a
  25. fixed interval $[a..b]$ of integers.}*/
  26. public:
  27. /*{Mcreation Q}*/
  28. b_priority_queue(int a, int b): (a,b)  {}
  29. /*{Mcreate creates an instance var of type name with information type 
  30.             $[a..b]$ and initializes it with the empty priority queue. }*/
  31. virtual ~b_priority_queue()  { }
  32. /*{Moperations 2 5.5 }*/
  33. /*{Mtext See section ref{Priority Queues}.}*/
  34. b_pq_item insert(K k,int info)
  35.                            { return b_heap::insert(info,Convert(k)); }
  36. void decrease_inf(b_pq_item it,int newinf)
  37.                            { b_heap::decrease_key(it,newinf); }
  38. void del_item(b_pq_item x) { b_heap::delete_item(x); }
  39. int      inf(b_pq_item x)  { return b_heap::key(x); }
  40. K  key(b_pq_item x)  { return LEDA_ACCESS(K,b_heap::info(x)); }
  41. K  del_min()         { return LEDA_ACCESS(K,b_heap::del_min()); }
  42. b_pq_item find_min()       { return b_heap::find_min(); }
  43. void clear()               { b_heap::clear(); }
  44. int empty()                { return (find_min()==0) ? true : false; }
  45. };
  46.  
  47. /*{Mimplementation
  48. Bounded priority queues are implemented by arrays of linear lists.
  49. Operations insert, find_min, del_item, decrease_inf, key, inf,
  50. and empty take time $O(1)$, del_min (=  del_item for the minimal
  51. element) takes time $O(d)$, where $d$ is the distance of the minimal
  52. element to the next bigger element in the queue (= $O(b-a)$ in the
  53. worst case). clear takes time $O(b-a+n)$ and the space requirement is
  54. $O(b-a+n)$, where $n$ is the current size of the queue.}*/
  55. #endif