| 22 | } |
| 23 | |
| 24 | public static void deleteDupsC(LinkedListNode head) { |
| 25 | if (head == null) return; |
| 26 | LinkedListNode previous = head; |
| 27 | LinkedListNode current = previous.next; |
| 28 | while (current != null) { |
| 29 | // Look backwards for dups, and remove any that you see. |
| 30 | LinkedListNode runner = head; |
| 31 | while (runner != current) { |
| 32 | if (runner.data == current.data) { |
| 33 | LinkedListNode tmp = current.next; |
| 34 | previous.next = tmp; |
| 35 | current = tmp; |
| 36 | /* We know we can't have more than one dup preceding |
| 37 | * our element since it would have been removed |
| 38 | * earlier. */ |
| 39 | break; |
| 40 | } |
| 41 | runner = runner.next; |
| 42 | } |
| 43 | |
| 44 | /* If runner == current, then we didn't find any duplicate |
| 45 | * elements in the previous for loop. We then need to |
| 46 | * increment current. |
| 47 | * If runner != current, then we must have hit the �break� |
| 48 | * condition, in which case we found a dup and current has |
| 49 | * already been incremented.*/ |
| 50 | if (runner == current) { |
| 51 | previous = current; |
| 52 | current = current.next; |
| 53 | } |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | public static void deleteDupsB(LinkedListNode head) { |
| 58 | if (head == null) return; |