Write a method removeDuplicates
that removes all consecutive duplicates from an unsorted linked list.
For example, if a variable list
contains the following values:
[8, 8, 3, 7, 2, 2, 2, 4, -1, -1, 9, 9, 9, 9, 9]
The call of list.removeDuplicates();
would modify the list to store the following values:
[8, 3, 7, 2, 4, -1, 9]
You must preserve the original relative order of the elements of the list.
Assume that you are adding this method to the LinkedIntList
class as defined below:
public class LinkedIntList {
private ListNode front; // null for an empty list
...
}