home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / jgl_1_1 / jgl_1_1.exe / examples / Stack1.java < prev    next >
Encoding:
Java Source  |  1996-09-10  |  942 b   |  40 lines

  1. // Copyright(c) 1996 ObjectSpace, Inc.
  2.  
  3. import java.util.Enumeration;
  4. import jgl.*;
  5.  
  6. /**
  7.  * Construction, enumeration, pushing, popping.
  8.  * <p>
  9.  * @see jgl.Stack
  10.  * @version 1.1
  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.  
  40.