(Item item)
| 43 | |
| 44 | // add the item to the front |
| 45 | public void addFirst(Item item) { |
| 46 | validate(item); |
| 47 | Node oldFirst = first; |
| 48 | first = new Node(); |
| 49 | first.item = item; |
| 50 | first.prev = null; |
| 51 | first.next = oldFirst; |
| 52 | if (isEmpty()) last = first; |
| 53 | else oldFirst.prev = first; |
| 54 | n++; |
| 55 | } |
| 56 | |
| 57 | // add the item to the back |
| 58 | public void addLast(Item item) { |