Question: Having learned of ADTs and algorithmic complexity, you can't wait to see how this works in practice. You will implement a simplified list interface. The
Having learned of ADTs and algorithmic complexity, you can't wait to see how this works in practice. You will implement a simplified list interface. The list interface has been given to you in ISimpleList.java.
Once implemented, you will write some client code for the list and do a simple complexity analysis of that code.
Part 1: You will write a class ArrayBasedList.java which implements the ISimpleList interface.
Your class will store the data in an array and it will have a double up growth policy. There is no automatic capacity reduction. Starter code has been given to you. All you need to do is fill in the rest. All your implemented methods should be as time and space efficient as possible. Give the time big O for each method you implement in the method header.
iSimpleList.java
public interface ISimpleList { /** * * @return the list size */ int size();
/** * Get the element at position index * * @param index * @return */ String get(int index);
/** * Add item e to the end of the list * * @param e */ void add(String e);
/** * Remove the element at index * * @param index */ void remove(int index);
/** * Remove ALL occurrences of element e from the list and return how many * were removed * * @param e the element to remove * @return how many occurrences of e were removed */ int remove(String e); }
ArrayBAsedList.java
public class ArrayBasedList implements ISimpleList {
String[] data = new String[2];
int size;
@Override
public int size() {
return size;
}
@Override
public String get(int index) {
return data[index];
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
