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