public T removeFirst() throws EmptyCollectionException { // Checking to see if the List is empty or not if ( isEmpty() ) throw new EmptyCollectionException("LinkedList"); Node<T> first = contents; contents = contents.getNext(); count--; return first.getItem(); }
/* * Throw exception if array is empty. */ if (unsortedArr[0] == null) { throw new EmptyCollectionException("Array"); }
throw new EmptyCollectionException("LinkedList"); Node < T > temp = contents; T next = contents.getNext().getItem(); contents = new Node ( next, contents ); count--; return temp.getItem();
/** * Get the object at the back of the queue. * * @return Object at the back of the queue. * * @exception EmptyCollectionException The queue is empty. */ public E getBack() throws EmptyCollectionException { if (isEmpty()) throw new EmptyCollectionException(); return list.get(list.size() - 1); }
/** * Get the object at the front of the queue. * * @return Object at the front of the queue. * * @exception EmptyCollectionException The queue is empty. */ public E getFront() throws EmptyCollectionException { if (isEmpty()) throw new EmptyCollectionException(); return list.get(0); }
/** * Remove and return the first object in the queue. * * @return Dequeued object. * * @exception EmptyCollectionException The queue is empty. */ public E remove() throws EmptyCollectionException { if (isEmpty()) throw new EmptyCollectionException(); return removeFirst(); }