home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jsamples.z / Stack1.java < prev    next >
Text File  |  1997-07-30  |  976b  |  39 lines

  1. // Copyright(c) 1996,1997 ObjectSpace, Inc.
  2.  
  3. import java.util.Enumeration;
  4. import COM.objectspace.jgl.*;
  5.  
  6. /**
  7.  * Construction, enumeration, pushing, popping.
  8.  *
  9.  * @see COM.objectspace.jgl.Stack
  10.  * @version 2.0.2
  11.  * @author ObjectSpace, Inc.
  12.  */
  13.  
  14. public class Stack1
  15.   {
  16.   public static void main( String[] args )
  17.     {
  18.     // Use an Slist as the underlying data structure.
  19.     Stack stack = new Stack();
  20.     stack.push( "bat" );
  21.     stack.push( "cat" );
  22.     stack.push( "dog" );
  23.  
  24.     System.out.println( "Print the Stack." );
  25.     System.out.println( stack );
  26.     System.out.println();
  27.  
  28.     System.out.println( "Non-destructively enumerate the Stack." );
  29.     Enumeration e = stack.elements();
  30.     while ( e.hasMoreElements() )
  31.       System.out.println( e.nextElement() );
  32.     System.out.println();
  33.  
  34.     System.out.println( "Pop and print each element." );
  35.     while ( !stack.isEmpty() )
  36.       System.out.println( stack.pop() );
  37.     }
  38.   }
  39.