/Users/petercappello/NetBeansProjects/56-2014/56-2014-example-JUnit/src/Stack.java |
import java.util.LinkedList;
import java.util.List;
A stack of objects of type T.
@author
public class Stack<T>
{
private final List<T> stack = new LinkedList<>();
Answers the question is the stack empty.
@return
public boolean isEmpty() { return stack.isEmpty(); }
Removes and retrieves the stack's top element.
@return
@throws
public T pop() { return stack.remove( 0 ); }
Inserts an element into the stack.
@param element
public void push( T element ) { stack.add( 0, element ); }
Retrieves but does not remove the top element of the stack.
@return
public T peek() { return stack.get( 0 ); }
}