Removes and returns the item on this queue that was least recently added. @return the item on this queue that was least recently added @throws NoSuchElementException if this queue is empty
()
| 110 | * @throws NoSuchElementException if this queue is empty |
| 111 | */ |
| 112 | public Item dequeue() { |
| 113 | if (isEmpty()) throw new NoSuchElementException("Queue underflow"); |
| 114 | Item item = first.item; |
| 115 | first = first.next; |
| 116 | n--; |
| 117 | if (isEmpty()) last = null; // to avoid loitering |
| 118 | return item; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Returns a string representation of this queue. |
no test coverage detected