@Test public void shouldReturnFalseIfListIsNotPalindromeReversing() { ListNode<Integer> list = createList(new int[] { 1, 1, 3 }); boolean result = palindromeList.checkReversing(list); assertFalse(result); }
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);  }