@Override public E top() throws EmptyStackException { if (isEmpty()) { throw new EmptyStackException("Stack is empty!"); } return top.getElement(); }
@Override public E pop() throws EmptyStackException { if (isEmpty()) { throw new EmptyStackException("Stack is empty"); } E element = top.getElement(); top = top.getNext(); size--; return element; }