//Johnny A. Shaieb //cs2003 //Lab10 //Sahasa public class SortedList implements SortedListInterface { // copy of code from our textbook pages 362-363 // modified slightly by rlw 2/24/03 private ListInterface aList; // constructor: public SortedList() { aList = new ListArrayBased(); } // end default constructor public SortedList(Object obj) { aList = new ListArrayBased(obj); } // sorted list operations: public boolean isEmpty() { return aList.isEmpty(); }// end isempty public int size() { return aList.size(); }// end size public void sortedAdd(Comparable newItem) { int newPosition = locateIndex(newItem); aList.add(newPosition, newItem); }// end sortedAdd public void sortedRemove(Comparable anItem) { aList.delete(anItem); }// end sortedRemove public Object get(int position) { return aList.get(position); }// end get public void display() { aList.display(); }// end display public int locateIndex(Comparable anItem) { int compvalue; if (aList.isEmpty()) { compvalue = 1; } else { int i = 1; while((i <= aList.size()) && (anItem.compareTo(aList.get(i)) > 0)) { i++; } compvalue = i; } return compvalue; }// end locateIndex }// end SortedList