Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class SortedArrayList extends List { private int size; private int capacity; private Object[] ls; // TODO: default: should create a sortedarraylist that is capable
public class SortedArrayListextends List { private int size; private int capacity; private Object[] ls; // TODO: default: should create a sortedarraylist that is capable of holding 10 element public SortedArrayList(){ } // TODO: second constructor - should create a sortedarraylist that is capable of holding x element that size public SortedArrayList(Class c, int capacity){ } public int size(){ return this.size; } public E get(int index) throws IndexOutOfBoundsException{ if(index >= this.size){ throw new IndexOutOfBoundsException(); } return (E) this.ls[index]; } // TODO: inserts element while maintaining the sorted order of the contents; resize to double capacity if no space public void add(E value) { } // TODO: delete - deletes an element at said index; moves elements such that there are no gaps in between them public void delete(int index) throws IndexOutOfBoundsException{ } // TODO: search - binary search O(log(n)) for the element; returns -1 if not found public int search(E value){ return -1; } // TODO: given some other sortedarraylist, compare it to see if it has the same contents (also in same order) public boolean equals(Object o){ return false; } // helper public String toString(){ String ret = ""; for(int i = 0; i < this.capacity; i++){ ret += i + ": "+ this.ls[i] + " "; } return ret; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started