ArrayList.java - public class ArrayList<T extends...

This preview shows page 1 - 2 out of 5 pages.

The preview shows page 1 - 2 out of 5 pages.
public class ArrayList<T extends Comparable<T>> implements List<T> {private T[] arrayList;private int size;private boolean isSorted;@Overridepublic boolean add(T element) {if (element == null) return false;if (this.size == arrayList.length) resizeArray();arrayList[size] = element;isSorted &= size == 0 || get(size-1).compareTo(element) <= 0;size++;// isSorted = checkSort(size);return true;}@Overridepublic boolean add(int index, T element) {if (element == null || checkSizing(index)) return false;if (this.size == arrayList.length) resizeArray();int i = size;while(i > index) {arrayList[i] = arrayList[i - 1];i--;}arrayList[index] = element;// isSorted &= (index == 0 || get(index-1).compareTo(element) <= 0) &&// (index + 1 == size || get(index+1).compareTo(element) >= 0);size++;isSorted = checkSort(size);return true;// if (element == null || checkSizing(index)) return false;// if (size == arrayList.length) resizeArray();// for (int i = size; i > index; i--) {// arrayList[i] = arrayList[i - 1];// }// arrayList[index] = element;// size++;// isSorted = false;// return true;}@Overridepublic void clear() {this.arrayList = (T[]) new Comparable[2]; //resetting arraylist to be emptythis.size = 0;isSorted = true;}@Overridepublic T get(int index) {if (checkSizing(index)) return null;return arrayList[index];}@Overridepublic int indexOf(T element) {int m = -1;

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 5 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Fall
Professor
N/A
Tags
Return statement, Void type, public class ArrayList

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture