Question: public class DataStructures_7 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here
public class DataStructures_7 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
QuickSort quickSort = new QuickSort();
int[] intArray = {5,3,1,9,8,2,4,7};
quickSort.quickSort(intArray,0, 7);
for(int i = 0; i
System.out.println(intArray[i] + " ");
}
//System.out.println("The answer after quick sort is " + k );
}
public class QuickSort {
public void quickSort(int[] intArray, int l, int r){
int s = hoarePartition(intArray , l , r);
if(l
quickSort(intArray, l, s-1);
quickSort(intArray, s + 1, r);
}
}
public int hoarePartition(int[] intArray, int l, int r){
int p = intArray[l];
int i = l + 1 ;
int j = r ;
while(l
ALGORITHM Quicksort(A[l..r )) in ito //Sorts a subarray by quicksortid .) //Input: Subarray of array A[O..n-1), defined by its left and right // indices I andr //Output: Subarray A[...] sorted in nondecreasing order JY UIT1010 fl
while(intArray[i]
i = i + 1;
}
while(intArray[j] > p){
j = j - 1;
}
int temp = intArray[i];
intArray[i] = intArray[j];
intArray[j] = temp;
}
WHEN I TRY TO RUN IT IT GIVES AN ERROR
if(i >= j){
int temp = intArray[i];
intArray[i] = intArray[j];
intArray[j] = temp;
temp = intArray[l];
intArray[l] = intArray[j];
intArray[j] = temp;
}
return j;
}
}
this is quick sort using hoares partition
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
