Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

image text in transcribed

image text in transcribed

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions

Question

* What is the importance of soil testing in civil engineering?

Answered: 1 week ago

Question

Explain the concept of shear force and bending moment in beams.

Answered: 1 week ago