Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Stack.java
- *
- * @author Lukas Goodman <lukasrossgoodman@gmail.com>
- */
- import java.util.*;
- /**
- * Implements a stack.
- */
- public class Stack<E> extends LinkedList<E> { //LIFO
- public E peek() {
- if (size() == 0)
- throw new EmptyStackException();
- return get(size() - 1);
- }
- public E pop() { // remove
- E removed = get(size() - 1);
- remove(size() - 1);
- return removed;
- }
- public E push(E item) { // add
- add(item);
- return item;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement