/Users/petercappello/NetBeansProjects/56-2014/56-2014-Generics/src/Stack.java
import java.util.LinkedList;

/**
 * A stack of objects.
 * @author Peter Cappello
 * @param <T> the reference type of the objects to be stacked.
 */
public class Stack<T>
{
    private final LinkedList<T> stack = new LinkedList<>();
    /**
     * Pop an element off the stack and return that element.
     * @return the stack's top element, if any. Otherwise, returns null. 
     */
    public T pop() { return isEmpty() ? null : stack.pop(); }
    
    public void push( T t ) { stack.push( t ); }
    
    public boolean isEmpty() { return stack.isEmpty(); }
    
    public static void main( String[] args )
    {
        Stack<Integer> myStack = new Stack<>();
        myStack.push( -3 );
        myStack.push( 73 );
        myStack.push( 953 );
        System.out.println("myStack.pop(): " + myStack.pop() );
        System.out.println("myStack.pop(): " + myStack.pop() );
        System.out.println("myStack.pop(): " + myStack.pop() );
        System.out.println("myStack.pop(): " + myStack.pop() );
        
        
        
        Stack myRawStack = new Stack(); // a stack of heterogenous objects.
        myRawStack.push( 9 );
        myRawStack.push( 9.0 );
        myRawStack.push( true );
        System.out.println("myRawStack.pop(): " + myRawStack.pop() );
        System.out.println("myRawStack.pop(): " + myRawStack.pop() );
        System.out.println("myRawStack.pop(): " + myRawStack.pop() );
        System.out.println("myRawStack.pop(): " + myRawStack.pop() );
        
        Stack<Number> myPolymorphicStack = new Stack<>();
        myPolymorphicStack.push( -3 );
        myPolymorphicStack.push( 73.0 );
        myPolymorphicStack.push( new Float( 20 ) );
        System.out.println("myPolymorphicStack.pop(): " + myPolymorphicStack.pop() );
        System.out.println("myPolymorphicStack.pop(): " + myPolymorphicStack.pop() );
        System.out.println("myPolymorphicStack.pop(): " + myPolymorphicStack.pop() );
        System.out.println("myPolymorphicStack.pop(): " + myPolymorphicStack.pop() );
    }
}