Question: For the implementation of List class by fixed size array approach, please write codes for the three member functions: constructor , insert , and retrieve

For the implementation of List class by fixed size array approach, please write codes for the three member functions: constructor, insert, and retrieve (marked red in the class declaration).

The class List is defined as follows:

//The List preserves the order of the elements

public class List{

private final T[] items;

private int size; // number of items in the list

private static final int DEFAULT_CAPACITY=20;

//Default constructor

public List() {

//TO DO

}

// To check if the list is empty or not

public boolean isEmpty() {

return size<=0;

}

// To get the length of the list

public int getLength() {

return size;

}

//To insert the newItem into the list at position index

//NOTE: 0<=index<=getlength()

public boolean insert(int index, T newItem) {

//TO DO

}

//To remove an item from the list at position index

//NOTE: 0<=index

public boolean remove(int index) {

//DONE

}

// To retrieve a list item by position index

// If 0<=index

public T retrieve(int index) {

//TO DO

}

}

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!