Question: write a method called insertAt that takes an index, an integer n, and a value as parameters and that inserts n copies of the given

write a method called insertAt that takes an index, an integer n, and a value as parameters and that inserts n copies of the given value at the given index in a list of intgers. For example a call to list.insertAt(2, 4, 88) will change this sequence:

[12, 42, 8, 988] to [12, 42, 88, 88, 88, 88, 8, 988]

You are writing a method for the ArrayIntList class:

public class ArrayIntList{

private int[] elementData; //list of integers

private in size; //current # of elements in the list

<.......methods......>

}

Your method checks the boudary condition and throws an illegalArgumentException if the index is less than 0 or greater than the number of elements in the list or if the value of n is less than 0. You are not to cal any other ArrayIntList methods to solve this problem, you are not allowed to define auxiliary data structure(no array, ArrayList, etc.), and your solution must run in )(n + m) time where n is the number of items to add and m is the length of the list. You may assume that the array has sufficient capacity to store the new values.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!