/**
 * A sample program to show how to use LinkedList as a stack.
 * @author Kiminori Matsuzaki
 */

import java.io.*;

/*
 * To use LinkedList class, you need to import java.util.LinkedList;
 */
import java.util.*;

/**
 * LinkedList provide many methods among which we use the following ones
 * to implemente a stack.
 *  - void addLast( Object o );   : push
 *  - Object removeLast( );       : pop
 *  - boolean isEmpty( );         
 */
class StackSample {
  public static void main( String[] args ) {
    /* create an empty stack */
    LinkedList stack = new LinkedList( );

    /* put values to stack */
    stack.addLast( "1st item" );
    stack.addLast( "2nd item" );

    /* output all the values in the stack */
    while ( !stack.isEmpty( ) ) {
      String value = ( String ) stack.removeLast( );
      System.out.println( value );
    }
  }
}
    
