logo CodeStepByStep logo

removeDuplicates

Related Links:

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
    ...
}
Partial class: Write code that will become part of an existing class as described. You do not need to write the complete class, just the portion described in the exercise.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.