home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / src / basic / _slist.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  2.2 KB  |  107 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  _slist.c
  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. #include <LEDA/slist.h>
  16.  
  17. //------------------------------------------------------------------------------
  18. // Members of class SLIST
  19. //------------------------------------------------------------------------------
  20.  
  21. SLIST::SLIST()      
  22. { h=0; 
  23.   t=0;
  24.   count=0;
  25.   iterator=0; 
  26. }
  27.  
  28. SLIST::SLIST(ent a) 
  29. { h=t=new slink(a,0);
  30.   count=1; 
  31.   iterator=0;  
  32. }
  33.  
  34. SLIST::SLIST(const SLIST& x)
  35. { slink* p = x.h;
  36.   h=0; 
  37.   t=0; 
  38.   count=0; 
  39.   iterator=0;
  40.   while (p) { append(p->e);     //copy new list
  41.               p = p->succ;}
  42. }
  43.  
  44. void SLIST::pop()    
  45. { if (iterator!=0) error_handler(1,"pop: deletion while iterator is active");
  46.   if (h) 
  47.   { if (t==h) t = 0;
  48.     slink* x=h; 
  49.     h=x->succ; 
  50.     clear_el(x->e);
  51.     delete x;
  52.     count--;
  53.    }
  54. }
  55.  
  56. slink* SLIST::push(ent a)   
  57. { if (iterator!=0) error_handler(2,"push: insertion while iterator is active");
  58.   copy_el(a);
  59.   count++;
  60.   h = new slink(a,h); 
  61.   if (t==0) t = h;
  62.   return h;
  63. }
  64.  
  65. slink* SLIST::append(ent a)
  66. { if (iterator!=0) error_handler(2,"append: insertion while iterator is active");
  67.   count++;
  68.   copy_el(a);
  69.   slink* p = new slink(a,0); 
  70.   if (t) t->succ = p; 
  71.   else   h = p;
  72.   return t=p;
  73.  
  74. slink* SLIST::append(SLIST& l)
  75. { if (iterator!=0) error_handler(2,"append: insertion while iterator is active");
  76.   slink* p = l.h;
  77.   while(p) { append(p->e);
  78.              p = p->succ;  }
  79.   return h;
  80.  
  81. slink* SLIST::cyclic_succ(slink* loc) const
  82. { if (loc==0) return 0;
  83.   return loc->succ? loc->succ : h;
  84. }
  85.  
  86. SLIST& SLIST::operator=(const SLIST& x)
  87. { slink* p = x.h;
  88.   iterator=0;
  89.   while (h) pop();              //destroy old list
  90.   while (p) { append(p->e);     //copy new list
  91.               p = p->succ;}
  92.   return *this;
  93. }
  94.  
  95. SLIST SLIST::operator+(SLIST x)  // concatenation
  96. { append(x);
  97.   return this;
  98. }
  99.  
  100. void SLIST::clear()
  101. { while (h) pop(); 
  102.   iterator=0;
  103. }
  104.