------------------------->  GNU Sather - sourcefile  <-------------------------
-- Copyright (C) 1995 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>  <--------------
--!!! THIS FILE HAS BEEN CREATED FROM a_stack.sa, DO NOT EDIT IT !!!
-- a_stack.sa: Array based stack
-- Author: Benedict A. Gomes <gomes@samosa.ICSI.Berkeley.EDU>


class NR_STACK{T} < $NR_STACK{T} is include NR_A_STACK{T} end;
-------------------------------------------------------------------

class NR_A_STACK{T} < $NR_STACK{T}
  is
   -- An array-based stack implemented by delegation to an FLIST{T},
   -- which allocates space by amortized doubling.
   
   

   private attr s: FLIST{T};
   
   create: SAME is
      res ::= new;
      
      res.s := #FLIST{T};
      return(res);
   end;

   create(e: $ELT{T}): SAME is
      -- Push the elements of "e" onto the stack.
      -- If "e" is an ordered collection this will push elements
      -- such that the last element is left at the top of the stack
      res ::= #SAME;
      loop res.push(e.elt!) end;
      return res;
   end;

   create_from(a: ARRAY{T}): SAME is
      return create(a);
   end;
      
   create_capacity(n: INT): SAME is
      -- Preallocate n empty elements 
      res ::= new;
      res.s := #FLIST{T}(n);
      
      return(res);
   end;
   
   remove:T is

         return pop; 
      
   end;
   
   current: T is 

	 return top ;
      
   end;
   
   push(e: T) pre ~void(self)  is

	 s := s.push(e);
      
   end;
   
   pop: T pre ~void(self) and ~is_empty is 

	 return(s.pop);
      
   end;
   
   top: T pre ~void(self) and ~is_empty is
      -- Return the  top element of the stack

	 return(s.top);
      
   end;
   
   reverse_elt!: T pre ~void(self) is
      -- Yield the elements of the stack in reverse order i.e.
      -- ending with "top". 

	 loop yield(s.elt!) end;
      
   end;

   elt!: T pre ~void(self) is

         loop yield s[(s.size-1).downto!(0)]; end;
      
   end;
   
   top!: T pre ~void(self) is
      -- Same as elt!

         loop yield s[(s.size-1).downto!(0)]; end;
      
   end;


   size: INT pre ~void(self) is return(s.size) end;
   
   is_empty: BOOL pre ~void(self) is return(size = 0) end;
   
   has(e: T): BOOL pre ~void(self) is

	 return(s.has(e));
      
   end;
   
   str: STR is

	 return s.str;
      
   end;

   
          copy: SAME pre ~void(self) is

	 res ::= create_capacity(size);
	 res.s := s.copy;
	 return res;
      
   end;
   
end;
-------------------------------------------------------------------   
