logo Practice-It logo

BJP5 Exercise 16.17: removeRange

Related Links:
Author: Whitaker Brand (on 2019/09/19)

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:

listRange.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
Type your solution here:

This is a partial class problem. Submit code that will become part of an existing Java class as described. You do not need to write the complete class, just the portion described in the problem.

You must log in before you can solve this problem.

Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.