Answered step by step
Verified Expert Solution
Link Copied!

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 SortedArrayList extends 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

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions