()
| 69 | |
| 70 | // remove and return the item from the front |
| 71 | public Item removeFirst() { |
| 72 | if (isEmpty()) throw new NoSuchElementException("Deque is empty"); |
| 73 | Item item = first.item; |
| 74 | Node oldFront = first; |
| 75 | first = oldFront.next; |
| 76 | oldFront.next = null; |
| 77 | n--; |
| 78 | if (isEmpty()) last = null; |
| 79 | else first.prev = null; |
| 80 | return item; |
| 81 | } |
| 82 | |
| 83 | // remove and return the item from the back |
| 84 | public Item removeLast() { |