Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 19 ArrayList - Coding Goal: Given the following ArrayList class, which is an ArrayList with a backingArray and a size variable (the same

image

Question 19 ArrayList - Coding Goal: Given the following ArrayList class, which is an ArrayList with a backingArray and a size variable (the same as your homework), implement the addAll(T[] arr, int index) method by selecting the correct option in the dropdown. This method will add every element from the inputted arr array variable to the backingArray, with the new elements starting at index index. This method must not delete any elements that were initially in the backing array, meaning any elements at or after index index must be shifted behind the new elements. Assumptions: You may assume that the list has a valid structure, but do not make any other assumptions about the size or ordering of the list. You may assume that the array passed into the method has at least one element and no null indices (i.e. length of the inputted array arr) is equal to the number of elements in it to copy over). You may assume that the backingArray is large enough to accommodate the new elements, so you do not need to perform any resize operation while adding. Example: Initial backingArray): [[0, 1, 2, 3, 4, 5, null, null, null, null] arr: [10, 11, 12] addAll(arr, 3) is called Final backingArray [0, 1, 2, 10, 11, 12, 3, 4, 5, null] public class ArrayList { 1 2 3 private T backingArray; private int size; // implementation omitted Adds all of the elements at the specified index @param arr the array of data to add to the specified index @param index the index to start adding the new data to / public void addAll(T[] arr, int index) { for (int i = size - 1; i >= index; i--) { 1. = backingArray[i]; } for (int i = 0; i < arr.length; i++) { = arr[i]; 2. 3. backingArray[i-arr.length] backingArray[i] 15 pts size + arr.length

Step by Step Solution

There are 3 Steps involved in it

Step: 1

The correct implementation for the addAll method in the given ArrayList class is as ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Electric Circuits

Authors: Matthew Sadiku, Charles Alexander

3rd Edition

978-0073301150, 0073301159

More Books

Students also viewed these Programming questions

Question

The commisions for purchasing bonds:

Answered: 1 week ago

Question

Copy and complete the statement. 3800 m ? km =

Answered: 1 week ago