Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
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

Step: 1

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

XML Data Management Native XML And XML Enabled Database Systems

Authors: Akmal Chaudhri, Awais Rashid, Roberto Zicari, John Fuller

1st Edition

0201844524, 978-0201844528

More Books

Students also viewed these Databases questions