Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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