package stack; import exceptions.EmptyStackException; import exceptions.FullStackException; import stack.utility.Node; /** * Created with MONSTER. * User: xgiovio * Date: 05/03/14 * Time: 0.12 */ public class NodeStack implements Stack { @Override public void push(E element) throws FullStackException { Node temp = new Node(element,stack); stack = temp; ++number_of_elements; } @Override public E top() throws EmptyStackException { if (isEmpty()) throw new EmptyStackException(); return stack.getElement(); } @Override public E pop() throws EmptyStackException { Node to_return; if (isEmpty()) { throw new EmptyStackException(); }else{ to_return = stack; stack = stack.getNext(); --number_of_elements; return to_return.getElement(); } } @Override public boolean isEmpty() { if (size() < 1) return true; return false; } @Override // not used public boolean isFull() { return false; } @Override public int size() { return number_of_elements; } private Node stack = null; private int number_of_elements = 0; }