Question: Write the ArrayList class using a fixed - size array provided in the picture. The class should implement the List interface. Taking this as a

Write the ArrayList class using a fixed-size array provided in the picture. The class should implement the List interface. Taking this as a base, modify the ArrayList so that it works circularly. That is, if elements would be inserted past the bounds of the array, they should wrap around to the other side. You can find the strategy for this with the circular array-based queue.
However, in this case it should be possible to insert elements anywhere within the
bounds of the list. Important info - waic class Arroylistse implaments List=163=03=k=k1;k-[k+1]=data[k];data[1]= You will need to keep track of the starting index of the list and the size of the list.
Knowing these and the length of the array will let you identify where the beginning and
the end of the list are. Note you will need modular arithmetic to do so, as shown in the
notes.
- Adding or removing at a certain index in the list will actually need to be offset. If the
list elements are at indices (6,7,8,9,0,1), then calling add(1, e) should actually
insert at index 7 of the array, and add(list.size(), e) or add(6, e) should insert at index 2.
Consider writing a helper method to perform this offset calculation.
- The bounds checking with checkIndex will also have to be modified, because the
start of the list is no longer guaranteed to be at 0.
- In case you need it, Java's modulo operator works in a way where taking a modulo on
a negative number will result in a negative number, which is not useful for indexing.
For example, (5+6)%10 is 1, but (5-6)%10 results in -1 instead of 9.
To fix this issue, compute these like (5-6+10)%10 instead.
Write the ArrayList class using a fixed - size

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 Programming Questions!