Question: Please help. The code has to return the amount of time it takes to run each operation (add one element, add to front, delete one

Please help. The code has to return the amount of time it takes to run each operation (add one element, add to front, delete one element) in nanoseconds.
Please help. The code has to return the amount of time it
takes to run each operation (add one element, add to front, delete
one element) in nanoseconds. Run code at least 5 times and record
the average value for each test TASK 1. Run the code, calculate
time it took in nano seconds to implement each operation. Provide a
screenshot of at least one successful run of the 3:34 public class
MyArrayList implements MyList { public static final int INITIAL_CAPACITY =16; private E]
data =(E[]) new Object[INITIAL_CAPACITY]; private int size =0;// Number of elements in
the list I Create an empty list % public MyArrayList() \{ \}

Run code at least 5 times and record the average value for each test TASK 1. Run the code, calculate time it took in nano seconds to implement each operation. Provide a screenshot of at least one successful run of the 3:34 public class MyArrayList implements MyList { public static final int INITIAL_CAPACITY =16; private E] data =(E[]) new Object[INITIAL_CAPACITY]; private int size =0;// Number of elements in the list I Create an empty list % public MyArrayList() \{ \} / Create a list from an array of objects * public MyArrayList(E[] objects) \{ for (int i =0;i size) throw new IndexOutOfBoundsException ("Index: " + index + ", Size: " + size); ensureCapacity(); // Move the elements to the right 3:34 // Move the elements to the right after the specified index for(inti=size1;i>=index;i-)data[i+1]=data[i]; // Insert new element to data[index] data[index] =e; // Increase size by 1 3size++; I Create a new larger array, double the current size +1/ private void ensureCapacity() \{ if (size >= data.length) \{ E[] newData =(E])( new Object [ size * 2+1]); System.arraycopy(data, 0 , newData, 0 , size); \}data= newData; \} @Override / Clear the list % public void clear() \{ data =(E[]) new Object[INITIAL_CAPACITY]; size =0; \} @Override l Return true if this list contains the element / public boolean contains(Object e) \{ for (int i=0;i= size) throw new IndexOutOfBoundsException size); ("Index: " + index + ", Size: " + \} @)Override / Return the index of the first matching element * in this list. Return 1 if no match. * public int indexOf(Object e) \{ for (int i=0;i=0;i) if (e.equals(data[i])) return i; \}return1; @Override / Remove the element at the specified position * in this list. Shift any subsequent elements to the left. * Return the element that was removed from the list. * public E remove(int index) \{ checklndex(index); E e = data[index]; // Shift data to the left for (int j= index; j iterator() \{ return new ArrayListlterator(); \} private class ArrayListlterator implements java.util.Iterator \{ private int current =0; // Current index @ Override public boolean hasNext() \{ return current (); /ladd 4 elements for (int i=1;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!