@Test public void testIsPalindrome() { LinkedList<Character> linkedList = new LinkedList<Character>(); linkedList.add('c'); linkedList.add('i'); linkedList.add('v'); linkedList.add('i'); linkedList.add('c'); assertTrue(isPalindrome(linkedList)); linkedList = new LinkedList<Character>(); linkedList.add('a'); linkedList.add('n'); linkedList.add('n'); linkedList.add('a'); assertTrue(isPalindrome(linkedList)); linkedList = new LinkedList<Character>(); linkedList.add('a'); linkedList.add('n'); linkedList.add('m'); linkedList.add('a'); assertFalse(isPalindrome(linkedList)); }
public static <E> boolean isPalindrome(LinkedList<E> linkedList) { int lastIdx = linkedList.size() - 1; for (int runningIdx = 0; runningIdx < lastIdx; runningIdx++, lastIdx--) { if (!linkedList.get(runningIdx).equals(linkedList.get(lastIdx))) { return false; } } return true; }
PracticeQuestionsCh2 { public static <E> boolean isPalindrome(LinkedList<E> linkedList) { int lastIdx = linkedList.size() - 1; for (int runningIdx = 0; runningIdx < lastIdx; runningIdx++, lastIdx--) { if (!linkedList.get(runningIdx).equals(linkedList.get(lastIdx))) { return false; } } return true; } }
PracticeQuestionsCh2 { public static <E> boolean isPalindrome(LinkedList<E> linkedList) { int lastIdx = linkedList.size() - 1; for (int runningIdx = 0; runningIdx < lastIdx; runningIdx++, lastIdx--) { if (!linkedList.get(runningIdx).equals(linkedList.get(lastIdx))) { return false; } } return true; }  }
PracticeQuestionsCh2 { public static <E> boolean isPalindrome(LinkedList<E> linkedList) { int lastIdx = linkedList.size() - 1; for (int runningIdx = 0; runningIdx < lastIdx; runningIdx++, lastIdx--) { if (!linkedList.get(runningIdx).equals(linkedList.get(lastIdx))) { return false; } } return true; }  static void removeDupes(LinkedList<E> linkedList); static void partition(LinkedList<E> linkedList, E pivot); static boolean isPalindrome(LinkedList<E> linkedList); static boolean isPalindromeVariant(LinkedList<E> linkedList); }
PracticeQuestionsCh2 { public static <E> boolean isPalindrome(LinkedList<E> linkedList) { int lastIdx = linkedList.size() - 1; for (int runningIdx = 0; runningIdx < lastIdx; runningIdx++, lastIdx--) { if (!linkedList.get(runningIdx).equals(linkedList.get(lastIdx))) { return false; } } return true; }  static void removeDupes(LinkedList<E> linkedList); static void partition(LinkedList<E> linkedList, E pivot); static boolean isPalindrome(LinkedList<E> linkedList); static boolean isPalindromeVariant(LinkedList<E> linkedList);  }