/** * Removes the first element from the list * @return The object which was contained in the first element */ public T removeHead() { if( first == null ) throw new IllegalArgumentException("Empty list"); T ret = first.getObject(); Element<T> e = first; available.push(first); if( first.next != null ) { first.next.previous = null; first = first.next; } else { // there's only one element in the list first = last = null; } e.clear(); size--; return ret; }
/** * Removes the last element from the list * @return The object which was contained in the lsat element */ public Object removeTail() { if( last == null ) throw new IllegalArgumentException("Empty list"); Object ret = last.getObject(); Element<T> e = last; available.add(last); if( last.previous != null ) { last.previous.next = null; last = last.previous; } else { // there's only one element in the list first = last = null; } e.clear(); size--; return ret; }
/** * Removes the first element from the list * @return The object which was contained in the first element */ public T removeHead() { if( first == null ) throw new IllegalArgumentException("Empty list"); T ret = first.getObject(); Element<T> e = first; available.push(first); if( first.next != null ) { first.next.previous = null; first = first.next; } else { // there's only one element in the list first = last = null; } e.clear(); size--; return ret; }
/** * Removes the last element from the list * @return The object which was contained in the lsat element */ public Object removeTail() { if( last == null ) throw new IllegalArgumentException("Empty list"); Object ret = last.getObject(); Element<T> e = last; available.add(last); if( last.previous != null ) { last.previous.next = null; last = last.previous; } else { // there's only one element in the list first = last = null; } e.clear(); size--; return ret; }