_list_pq.c
Upload User: gzelex
Upload Date: 2007-01-07
Package Size: 707k
Code Size: 1k
Development Platform:

MultiPlatform

  1. /*******************************************************************************
  2. +
  3. +  LEDA-R  3.2.3
  4. +
  5. +  _list_pq.c
  6. +
  7. +  Copyright (c) 1995  by  Max-Planck-Institut fuer Informatik
  8. +  Im Stadtwald, 66123 Saarbruecken, Germany     
  9. +  All rights reserved.
  10. *******************************************************************************/
  11. #include <LEDA/impl/list_pq.h>
  12. list_pq::list_pq(const list_pq&) { /* copy constructor */}
  13. list_pq& list_pq::operator=(const list_pq&) { /* assignment */ return *this; }
  14. list_pq_item list_pq::insert(GenPtr k,GenPtr i) 
  15. { copy_key(k);
  16.   copy_inf(i); 
  17.   list_pq_item p = new list_pq_elem(k,i,nil,head);
  18.   if (head) head->pred = p;
  19.   head = p;
  20.   count++;
  21.   return p; 
  22. }
  23. list_pq_item list_pq::find_min() const  
  24. { list_pq_item p = head;
  25.   list_pq_item m = head;
  26.   if (int_type())
  27.      while (p)
  28.      { if (LEDA_ACCESS(int,p->key) < LEDA_ACCESS(int,m->key)) m = p;
  29.        p = p->succ;
  30.       }
  31.   else
  32.      while (p)
  33.      { if (cmp(p->key,m->key) < 0) m = p;
  34.        p = p->succ;
  35.       }
  36.   return m;
  37.  }
  38. void list_pq::del_item(list_pq_item it)     
  39. { list_pq_item p = it->pred;
  40.   list_pq_item s = it->succ;
  41.   if (p) p->succ = s;
  42.   else   head = s;
  43.   if (s) s->pred = p;
  44.   count--;
  45.  }
  46. void list_pq::clear()   
  47. { while (head)
  48.   { list_pq_item p = head->succ;
  49.     clear_key(head->key);
  50.     clear_inf(head->inf);
  51.     delete head;
  52.     head = p;
  53.    }
  54.   count = 0;
  55.  }