Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Implement a BlockedList class that implements the List interface. You may use any of the classes in JCF or in the textbook code. The

image text in transcribed
image text in transcribed
image text in transcribed
1. Implement a BlockedList class that implements the List interface. You may use any of the classes in JCF or in the textbook code. The constructor for this class takes an integer block size b and the implementation should have these performance characteristics: 1. get(i) and set(i,x) should run in 0(1) time per operation 2. add(1X) and remove(i) should run in O( b + min{ i , n-t )/ b ) amortized time : per operation. package comp248202 import java.util.Abstractlist import java.utit.Collection * This is a copy of the 3CF class ArrayList. It implements the List interface as a single array a. Elenents are stored at positions atel...alsize()-11. Doubling/hatving is used to resize the array * a when necessary * gauthor morin * eparan the type of objects stored in the List public class BlockedListeTs extends AbstractlisteTs t + keeps track of the class of objects we store FactoryeTs f /44 * The number of elenents stored int ni 14* * The block size int b; Constructor + eparam t the type of objects that are stored in this 1ist : param b the block are stored + @param b the block size public BlockedList (ClasseT> t, int b) t fnew Factory T>(t) n-8; //this.b b public int size) return ni public T get(int i) 4 I TODD: Implement this if (i n) throw new IndexOutofBoundsException): public T remove(int i) ( I TODO: Implement this it (ie 11 n- 1) throw new IndexoutofBoundsException) return null: package comp2482a2 import java. lang.reflect.Array * An ugly little class for attocating objects and arrays of generic * type T. This is needed to work around linitations df Java generics. public class FactoryeT> ClasseT> ti /e8 * Return the type associated with this factory * ereturn public ClasseT> type) return t: /ea * Constructor creates a factory for creating objects and * arrays of type t(T) * eparan te public Factory(ClasseT> te) t te: ak Allocate a new array of objects of type T. * eparam n the size of the array to allocate * ereturn the array allocated eSuppressWarnings(f"unchecked" ) protected TIl newArray(int n) f return (TII)Array.newInstance(t, n): 1s * ereturn public T newInstance() ( T x: try f xt.getDeclaredConstructor().newInstance(): h catch (Exception e) t x = null; return x

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

More Books

Students also viewed these Databases questions

Question

Discuss diversity management.

Answered: 1 week ago

Question

=+2 Why are so many countries bothered by their brain drains?

Answered: 1 week ago