Question: Second Image is starting code thanks for the help CS 143 Assignment 2 (IAList addBefore) In class, we implemented an IntArrayList class which internally had

 Second Image is starting code thanks for the help CS 143Assignment 2 (IAList addBefore) In class, we implemented an IntArrayList class which

Second Image is starting code thanks for the help

CS 143 Assignment 2 (IAList addBefore) In class, we implemented an IntArrayList class which internally had an array of integers but made it easy to add new elements to the end. We saw that after improvements, adding n elements to an IntArray would only take O(n) time. It accomplished this by doubling the underlying size of the array and copying the old array every time it ran out of space. If n total elements are added to the array, in the worst case, the array might have run out of space and had to copy itself when the very last (nth) element was added, when the nd element was 2 added, "th,"th, and so on down to the starting size of the array. Every time the array runs out of space, it needs to copy all the elements from the old array to the new array. However, even as n becomes very large and this series becomes arbitrarily long, n + + + + + ... = length) { throw new IndexOutOfBoundsException(i+""); return a[i]; // Retrieve the element at position i } public int size) { // Number of added elements, 0(1) // THE NEW DATA FIELD(S) MAY CHANGE THE WAY SIZE WORKS. return length; // The number of added elements } public void set(int i, int x) { // Modify an existing element, 0(1) // THE NEW DATA FIELD(S) MAY CHANGE THE WAY SET WORKS. if (i = length) { throw new IndexOutOfBoundsException(i+""); a[i] = x; // Change the existing element at position i to x } public void add(int x) { // Add an element to the end, O(n) for n // THE NEW DATA FIELD(S) MAY CHANGE THE WAY ADD WORKS. if (length >= a. length) { // Create new array of double the length int[] b = new int[a. length * 2]; // Copy the elements of a to the corresponding indexes of b for (int i = 0; i = length) { throw new IndexOutOfBoundsException(i+""); return a[i]; // Retrieve the element at position i } public int size) { // Number of added elements, 0(1) // THE NEW DATA FIELD(S) MAY CHANGE THE WAY SIZE WORKS. return length; // The number of added elements } public void set(int i, int x) { // Modify an existing element, 0(1) // THE NEW DATA FIELD(S) MAY CHANGE THE WAY SET WORKS. if (i = length) { throw new IndexOutOfBoundsException(i+""); a[i] = x; // Change the existing element at position i to x } public void add(int x) { // Add an element to the end, O(n) for n // THE NEW DATA FIELD(S) MAY CHANGE THE WAY ADD WORKS. if (length >= a. length) { // Create new array of double the length int[] b = new int[a. length * 2]; // Copy the elements of a to the corresponding indexes of b for (int i = 0; i

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!