Question: Sorting Objects with the Quicksort Algorithm The IntQuickSorter class presented in this chapter sorts an array of int values. Create an ObjectQuickSorter class that can

Sorting Objects with the Quicksort Algorithm The IntQuickSorter class presented in this chapter sorts an array of int values. Create an ObjectQuickSorter class that can sort Comparable objects. Demonstrate the class in a program that sorts an array of String objects. (java)

intquicksorter class in java

public class quicksort { public static void quickSort(int[] arr) { doQuickSort(arr,0,arr.length-1); }

private static void doQuickSort(int a[], int start, int end) { int pivot;

if(start < end) { pivot = partition(a,start,end);

doQuickSort(a,start,pivot - 1);

doQuickSort(a, pivot + 1, end); } }

private static int partition(int ar[], int start, int end) { int pivotval,endoflist,mid;

mid = (start + end) / 2;

swap(ar,start,mid);

pivotval = ar[start];

endoflist = start;

for(int i = start + 1; i <= end; i++) { if(ar[i] < pivotval) { endoflist++; swap(ar,endoflist,i); } }

swap(ar,start,endoflist);

return endoflist; }

private static void swap(int[] array, int a, int b) { int temp; temp = array[a]; array[a] = array[b]; array[b] = temp; } }

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!