@Test public void testRemoveDupes() { LinkedList<Integer> linkedList = new LinkedList<Integer>(); linkedList.add(1); linkedList.add(2); linkedList.add(1); removeDupes(linkedList); assertEquals(2, linkedList.size()); assertEquals(Integer.valueOf(1), linkedList.remove()); assertEquals(Integer.valueOf(2), linkedList.remove()); assertEquals(0, linkedList.size()); }
public static <E> void removeDupes(LinkedList<E> linkedList) { Set<E> dupes = new HashSet<E>(); LinkedListNode<E> current = linkedList.head().successor(); E data = null; for (int idx = 0; idx < linkedList.size(); idx++) { data = current.data(); current = current.successor(); if (dupes.contains(data)) { linkedList.remove(idx); } else { dupes.add(data); } } }
PracticeQuestionsCh2 { public static <E> void removeDupes(LinkedList<E> linkedList) { Set<E> dupes = new HashSet<E>(); LinkedListNode<E> current = linkedList.head().successor(); E data = null; for (int idx = 0; idx < linkedList.size(); idx++) { data = current.data(); current = current.successor(); if (dupes.contains(data)) { linkedList.remove(idx); } else { dupes.add(data); } } } }
PracticeQuestionsCh2 { public static <E> void removeDupes(LinkedList<E> linkedList) { Set<E> dupes = new HashSet<E>(); LinkedListNode<E> current = linkedList.head().successor(); E data = null; for (int idx = 0; idx < linkedList.size(); idx++) { data = current.data(); current = current.successor(); if (dupes.contains(data)) { linkedList.remove(idx); } else { dupes.add(data); } } }  }
PracticeQuestionsCh2 { public static <E> void removeDupes(LinkedList<E> linkedList) { Set<E> dupes = new HashSet<E>(); LinkedListNode<E> current = linkedList.head().successor(); E data = null; for (int idx = 0; idx < linkedList.size(); idx++) { data = current.data(); current = current.successor(); if (dupes.contains(data)) { linkedList.remove(idx); } else { dupes.add(data); } } }  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> void removeDupes(LinkedList<E> linkedList) { Set<E> dupes = new HashSet<E>(); LinkedListNode<E> current = linkedList.head().successor(); E data = null; for (int idx = 0; idx < linkedList.size(); idx++) { data = current.data(); current = current.successor(); if (dupes.contains(data)) { linkedList.remove(idx); } else { dupes.add(data); } } }  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);  }