Question: Please take a look at my quicksort code, and help me combine the sorted lists back to the original list that was passed as a

Please take a look at my quicksort code, and help me combine the sorted lists back to the original list that was passed as a parameter. I don't know how to quite do that.

/** * Quicksort algorithm to sort objects in a list * that implements the IndexedUnsortedList interface, * using compareTo() method defined by class of objects in list. * DO NOT MODIFY THIS METHOD SIGNATURE * * @param * The class of elements in the list, must extend Comparable * @param list * The list to be sorted, implements IndexedUnsortedList interface */ private static > void quicksort(IndexedUnsortedList list) { // TODO: Implement recursive quicksort algorithm if(list.isEmpty() || list.size() == 1) { return; } WrappedDLL lesser = new WrappedDLL(); WrappedDLL greater = new WrappedDLL(); T pivot = list.remove(list.last()); for(T i: list) if(i.compareTo(pivot) < 0) { lesser.add(i); } else if(i.compareTo(pivot) > 0) { greater.add(i); } quicksort(lesser); quicksort(greater); list.add(pivot); // is this correct? } /** * Quicksort algorithm to sort objects in a list * that implements the IndexedUnsortedList interface, * using the given Comparator. * DO NOT MODIFY THIS METHOD SIGNATURE * * @param * The class of elements in the list * @param list * The list to be sorted, implements IndexedUnsortedList interface * @param c * The Comparator used */ private static void quicksort(IndexedUnsortedList list, Comparator c) { // TODO: Implement recursive quicksort algorithm using Comparator if(list.isEmpty() || list.size() == 1) { return; } WrappedDLL lesser = new WrappedDLL(); WrappedDLL greater = new WrappedDLL(); T pivot = list.remove(list.last()); T i; while(!list.isEmpty()) { i = list.remove(list.first()); if(c.compare(i, pivot) < 0) { lesser.add(i); } else if(c.compare(i, pivot)> 0) { greater.add(i); } } quicksort(lesser,c); quicksort(greater,c); list.add(pivot); // is this correct?

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!