java.util.LinkedList Implementation
public class Stack<T> implements Iterable<T> {
private Deque<T> list = new LinkedList<>();
public boolean isEmpty() {
return list.isEmpty();
}
public int size() {
return list.size();
}
public void push(T value) {
list.addLast(value);
}
public T peek() {
if (isEmpty()) {
throw new EmptyStackException();
}
return list.peekLast();
}
public T pop() {
if (isEmpty()) {
throw new EmptyStackException();
}
return list.removeLast();
}
@Override
public Iterator<T> iterator() {
return list.iterator();
}
}