Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions