------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 1994 by International Computer Science Institute            --
-- This file is part of the GNU Sather library. It is free software; you may --
-- redistribute  and/or modify it under the terms of the GNU Library General --
-- Public  License (LGPL)  as published  by the  Free  Software  Foundation; --
-- either version 2 of the license, or (at your option) any later version.   --
-- This  library  is distributed  in the  hope that it will  be  useful, but --
-- WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY --
-- or FITNESS FOR A PARTICULAR PURPOSE. See Doc/LGPL for more details.       --
-- The license text is also available from:  Free Software Foundation, Inc., --
-- 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA                     --
-------------->  Please email comments to <bug-sather@gnu.org>  <--------------

-- next.sa: Inherited by elements of singly linked lists.
-------------------------------------------------------------------
abstract class $NEXT{T < $NEXT{T}} is
   -- The interface obeyed by classes which include NEXT{T}.

   next:T;			-- Pointer to next element in list, if any.
   
   next(e:T);			-- Set next pointer to `e'.
   
   size:INT;			-- The number of elements in the list
      -- starting with self. Self may be void.

   insert(e:T);			-- Insert the single element `e' after self.
      -- Neither may be void.

   append(l:T);			-- Append the list `l' to the end of the
      -- list self. self may not be void but `l' may be.
end;

-------------------------------------------------------------------
class NEXT{T < $NEXT{T}} < $NEXT{T} is
   -- Inherited by classes whose objects need to point to a list of
   -- objects of type T. Classes which inherit this get a `next'
   -- pointer and some features to manipulate it. It doesn't suport
   -- circular lists.
   
   attr next:T;		-- Pointer to next element in list, if any.
   
   size:INT is
      -- The number of elements in the list starting with self.
      -- Self may be void.
      if void(self) then return 0 end;
      r::=1; n::=next;
      loop until!(void(n)); r:=r+1; n:=n.next end;
      return r end;

   insert(e:T)
      -- Insert the single element `e' after self. Neither may be void,
      -- `e.next' must be void.
      pre ~void(self) and ~void(e) and void(e.next) is      
      e.next:=next; next:=e end;

   append(l:T) 
      -- Append the list `l' to the end of the list self. self may
      -- not be void but `l' may be.
      pre ~void(self) is
      if void(next) then next:=l; return end;
      last::=next; loop until!(void(last.next)); last:=last.next end;
      last.next:=l end;

end;

-------------------------------------------------------------------

