package lab2; import java.util.*;import java.lang.annotation.*; public class YorkArrayList implements List { /** * Initial size, default size, for the Array list */// ALREADY IMPLEMENTED; DO NOT...

package lab2;
import java.util.*;import java.lang.annotation.*;


public class YorkArrayList implements List {

/** * Initial size, default size, for the Array list */// ALREADY IMPLEMENTED; DO NOT MODIFYpublic static final int INITSIZE = 16;

/** * * Stores the elements of the array list Remember that you can not instantiate * an array of E[], but you can instantiate an array of Object and then typecast * it. */// ALREADY IMPLEMENTED; DO NOT MODIFYprivate E[] data = (E[]) new Object[INITSIZE];

/** * current number of elements */// ALREADY IMPLEMENTED; DO NOT MODIFYprivate int size = 0;

/** * No argument constructor */public YorkArrayList() {// TODO: Your implementation of this method starts here}/** * Constructor takes array of elements and then add then to * the end of the Array list * @param objects */public YorkArrayList(E[] objects) {data = (E[]) new Object[INITSIZE]; }


@Overridepublic int size() {// TODO: Your implementation of this method starts here return size;}

@Overridepublic boolean isEmpty() {// TODO: Your implementation of this method starts here return size == 0;}

/* * Add time complexity annotation taken by this method (@TimeComplexity). * Justify the time complexity inside the method body with TCJ */@TimeComplexity(value = "")@Overridepublic E get(int i) throws IndexOutOfBoundsException {// TODO: Your implementation of this method starts hereindexCheck(i,size);return data[i];}/* * Add time complexity annotation taken by this method (@TimeComplexity). * Justify the time complexity inside the method body with TCJ */@TimeComplexity(value = "")@Overridepublic E set(int i, E e) throws IndexOutOfBoundsException {// TODO: Your implementation of this method starts hereE tNum = data[i];data[i]= e; return tNum;



}

/* * Add time complexity annotation taken by this method (@TimeComplexity). * Justify the time complexity inside the method body with TCJ */@TimeComplexity(value = "")@Overridepublic void add(int i, E e) {// TODO: Your implementation of this method starts hereindexCheck(i,size); if(size == data.length) { E[] tData =(E[]) new Object[2*data.length]; for(int k =0 ; k tData[k] = data[k]; } data = tData; } for(int k = size -1 ; k>= i;k--) data[k+1] = data[k]; data[i] = e; size++;

}

/* * Add time complexity annotation taken by this method (@TimeComplexity). * Justify the time complexity inside the method body with TCJ */@TimeComplexity(value = "")@Overridepublic E remove(int i) throws IndexOutOfBoundsException {// TODO: Your implementation of this method starts hereindexCheck(i,size);E tData = data[i];for (int k = i; kdata[k] = data[k+1];}data[size-1] = null;size--; return tData;

}







/* * Add time complexity annotation taken by this method (@TimeComplexity). * Justify the time complexity inside the method body with TCJ */@TimeComplexity(value = "")@Overridepublic boolean contains(E e) throws NullPointerException {// TODO: Your implementation of this method starts here return true;

}

/* * Add time complexity annotation taken by this method (@TimeComplexity). * Justify the time complexity inside the method body with TCJ */@TimeComplexity(value = "")@Overridepublic boolean remove(E e) throws NullPointerException {// TODO Auto-generated method stub return false;

}/* * Add time complexity annotation taken by this method (@TimeComplexity). * Justify the time complexity inside the method body with TCJ */@TimeComplexity(value = "")@Overridepublic boolean addAll(List otherList) throws NullPointerException {// TODO Auto-generated method stub return false;

}

/* * Add time complexity annotation taken by this method (@TimeComplexity). * Justify the time complexity inside the method body with TCJ */@TimeComplexity(value = "")@Overridepublic boolean removeAll(List otherList) throws NullPointerException {// TODO Auto-generated method stub return false;

}

/* * Add time complexity annotation taken by this method (@TimeComplexity). * Justify the time complexity inside the method body with TCJ */@TimeComplexity(value = "")@Overridepublic boolean retainAll(List otherList) throws NullPointerException {// TODO Auto-generated method stub return false;

}/** * Return String value represent the content of list as * example "[30, 110, -110, -2, 1322]" */@Overridepublic String toString() {// TODO: Your implementation of this method starts here return new String();}@Overridepublic Iterator iterator() {// TODO: Your implementation of this method starts here return null;

}private void indexCheck(int i, int n) throws IndexOutOfBoundsException{if(i < 0="" ||="" i="">= n) {throw new IndexOutOfBoundsException("Illegal index:" + i);}}}
Sep 28, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here