home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sa104os2.zip / SATHR104.ZIP / SATHER / LIBRARY / NEXT.SA < prev    next >
Text File  |  1994-10-25  |  2KB  |  62 lines

  1. -- Copyright (C) International Computer Science Institute, 1994.  COPYRIGHT  --
  2. -- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
  3. -- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in    --
  4. -- the file "Doc/License" of the Sather distribution.  The license is also   --
  5. -- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA.  --
  6. --------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
  7.  
  8. -- next.sa: Inherited by elements of singly linked lists.
  9. -------------------------------------------------------------------
  10. type $NEXT{T} is
  11.    -- The interface obeyed by classes which include NEXT{T}.
  12.  
  13.    next:T;            -- Pointer to next element in list, if any.
  14.    
  15.    next(e:T);            -- Set next pointer to `e'.
  16.    
  17.    size:INT;            -- The number of elements in the list
  18.       -- starting with self. Self may be void.
  19.  
  20.    insert(e:T);            -- Insert the single element `e' after self.
  21.       -- Neither may be void.
  22.  
  23.    append(l:T);            -- Append the list `l' to the end of the
  24.       -- list self. self may not be void but `l' may be.
  25. end;
  26.  
  27. -------------------------------------------------------------------
  28. class NEXT{T} is
  29.    -- Inherited by classes whose objects need to point to a list of
  30.    -- objects of type T. Classes which inherit this get a `next'
  31.    -- pointer and some features to manipulate it. It doesn't suport
  32.    -- circular lists.
  33.    
  34.    attr next:T;        -- Pointer to next element in list, if any.
  35.    
  36.    size:INT is
  37.       -- The number of elements in the list starting with self.
  38.       -- Self may be void.
  39.       if void(self) then return 0 end;
  40.       r::=1; n::=next;
  41.       loop until!(void(n)); r:=r+1; n:=n.next end;
  42.       return r end;
  43.  
  44.    insert(e:T)
  45.       -- Insert the single element `e' after self. Neither may be void,
  46.       -- `e.next' must be void.
  47.       pre ~void(self) and ~void(e) and void(e.next) is      
  48.       e.next:=next; next:=e end;
  49.  
  50.    append(l:T) 
  51.       -- Append the list `l' to the end of the list self. self may
  52.       -- not be void but `l' may be.
  53.       pre ~void(self) is
  54.       if void(next) then next:=l; return end;
  55.       last::=next; loop until!(void(last.next)); last:=last.next end;
  56.       last.next:=l end;
  57.  
  58. end;
  59.  
  60. -------------------------------------------------------------------
  61.  
  62.