@Test(expected = IllegalArgumentException.class) public void shouldNotAcceptNullListAsInputReversing() { palindromeList.checkReversing(null); }
public boolean checkReversing(ListNode list) { validateInput(list); ListNode<Integer> reversedList = reverseLinkedList.reverseIterative(list); boolean isPalindrome = true; while (list != null) { isPalindrome = list.equals(reversedList); if (!isPalindrome) { break; } reversedList = reversedList.getNext(); list = list.getNext(); } return isPalindrome; }
PalindromeList { public boolean checkReversing(ListNode list) { validateInput(list); ListNode<Integer> reversedList = reverseLinkedList.reverseIterative(list); boolean isPalindrome = true; while (list != null) { isPalindrome = list.equals(reversedList); if (!isPalindrome) { break; } reversedList = reversedList.getNext(); list = list.getNext(); } return isPalindrome; } }
PalindromeList { public boolean checkReversing(ListNode list) { validateInput(list); ListNode<Integer> reversedList = reverseLinkedList.reverseIterative(list); boolean isPalindrome = true; while (list != null) { isPalindrome = list.equals(reversedList); if (!isPalindrome) { break; } reversedList = reversedList.getNext(); list = list.getNext(); } return isPalindrome; } PalindromeList(); }
PalindromeList { public boolean checkReversing(ListNode list) { validateInput(list); ListNode<Integer> reversedList = reverseLinkedList.reverseIterative(list); boolean isPalindrome = true; while (list != null) { isPalindrome = list.equals(reversedList); if (!isPalindrome) { break; } reversedList = reversedList.getNext(); list = list.getNext(); } return isPalindrome; } PalindromeList(); boolean checkReversing(ListNode list); boolean checkIterative(ListNode list); }
PalindromeList { public boolean checkReversing(ListNode list) { validateInput(list); ListNode<Integer> reversedList = reverseLinkedList.reverseIterative(list); boolean isPalindrome = true; while (list != null) { isPalindrome = list.equals(reversedList); if (!isPalindrome) { break; } reversedList = reversedList.getNext(); list = list.getNext(); } return isPalindrome; } PalindromeList(); boolean checkReversing(ListNode list); boolean checkIterative(ListNode list);  }