logo CodeStepByStep logo

removeRange

Related Links:

Write a method removeRange that accepts a starting and ending index as parameters and removes the elements at those indexes (inclusive) from the list. For example, if a variable list stores the following values:

[8, 13, 17, 4, 9, 12, 98, 41, 7, 23, 0, 92]

And the following call is made:

list.removeRange(3, 8);

Then the values between index 3 and index 8 (the value 4 and the value 7) are removed, leaving the following list:

[8, 13, 17, 23, 0, 92]

You should throw an IllegalArgumentException if either of the positions is negative. Otherwise you may assume that the positions represent a legal range of the list (0 <= start index <= end index < size of 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.