Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Remove an item from the end of the list */
- public void removeFromRear() {
- if (head == null) { // 1
- throw new IndexOutOfBoundsException("The linked list is empty."); // 1
- } else if (size == 1) { // 2
- head = null; // 2
- } else { // 3
- Node<Item> current = head; // 3
- while (current.next.next != null) { // 4
- current = current.next; // 4
- } // 4
- current.next = null; // 5
- }
- size--; // 6
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement