Question: MyList is the class name int capacity() returns the current capacity of the list boolean isEmpty() returns true if no items are in list (size

MyList is the class name

int capacity()

returns the current capacity of the list

boolean isEmpty()

returns true if no items are in list (size == 0)

int size()

returns the number of items in the list

boolean contains(TYPE e)

returns true if the list contains e

TYPE[] toArray(TYPE[] array)

moves items from the list into array and returns the array, note that array must have been instantiated to the size of the list (not the capacity)

void add(TYPE e)

adds item e to the end of the list, lengthening the list if necessary

void add(int index, TYPE e)

Inserts item e at position index moving items if necessary, if index is greater than current size, add e to the end of the list, if index is negative, insert e to the front of the list

boolean remove(TYPE e)

remove the first occurrence of item e from the list, moving elements if necessary, return false if e is not in the list, true otherwise

boolean remove(int index)

remove item at index from the list, moving elements if necessary, return false if there is no item at index

void clear()

remove all items from the list (set size to 0)

TYPE get(int index)

return item at index, null if there is no item at index

int set(int index,TYPE e)

replace item at index with e and return e, return null if there is no item at index (index less than 0 or greater than size)

int indexOf(TYPE e)

return the index of the first occurrence of e, -1 if it is not in the list

int lastIndexOf(TYPE e)

return the index of the last occurrence of e, -1 if it is not in the list

Iterator iterator()

return an iterator for the list

MyList()

sets the capacity to 10, growth factor is 2 (capacity doubles when necessary)

MyList(int c, int g)

sets capacity to c, growth factor is g (number of spaces to add when necessary)

 MyList is the class name int capacity() returns the current capacity

of the list boolean isEmpty() returns true if no items are in

list (size == 0) int size() returns the number of items in

You will demonstrate your code with the following main function. It should be placed in a separate class, not the MyList class public static void main (String[] args) f construct a list MyList ml -new MyList() System.out.println("empty: "ml.isEmpty()); add some nodes to it for (int i-e; i mlt = ml. iterator(); while (mlit.hasNext())f =" ) ; System.out.println(mlit.next()); --clear the list ml.clear); System.out.println(ml.size)" of" for (inti e; i ml -new MyList() System.out.println("empty: "ml.isEmpty()); add some nodes to it for (int i-e; i mlt = ml. iterator(); while (mlit.hasNext())f =" ) ; System.out.println(mlit.next()); --clear the list ml.clear); System.out.println(ml.size)" of" for (inti e; 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!