@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullElementsIterative() { reverseLinkedList.reverseIterative(null); }
public ListNode reverseIterative(ListNode list) { validateInput(list); if (list.getNext() == null) { return list; } ListNode head = null; ListNode current = list; while (current != null) { ListNode save = current; current = current.getNext(); save.setNext(head); head = save; } return head; }
ReverseLinkedList { public ListNode reverseIterative(ListNode list) { validateInput(list); if (list.getNext() == null) { return list; } ListNode head = null; ListNode current = list; while (current != null) { ListNode save = current; current = current.getNext(); save.setNext(head); head = save; } return head; } }
ReverseLinkedList { public ListNode reverseIterative(ListNode list) { validateInput(list); if (list.getNext() == null) { return list; } ListNode head = null; ListNode current = list; while (current != null) { ListNode save = current; current = current.getNext(); save.setNext(head); head = save; } return head; }  }
ReverseLinkedList { public ListNode reverseIterative(ListNode list) { validateInput(list); if (list.getNext() == null) { return list; } ListNode head = null; ListNode current = list; while (current != null) { ListNode save = current; current = current.getNext(); save.setNext(head); head = save; } return head; }  ListNode reverseIterative(ListNode list); ListNode<Integer> reverseRecursive(ListNode list); }
ReverseLinkedList { public ListNode reverseIterative(ListNode list) { validateInput(list); if (list.getNext() == null) { return list; } ListNode head = null; ListNode current = list; while (current != null) { ListNode save = current; current = current.getNext(); save.setNext(head); head = save; } return head; }  ListNode reverseIterative(ListNode list); ListNode<Integer> reverseRecursive(ListNode list);  }