Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
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
image text in transcribed
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

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

DB2 11 The Ultimate Database For Cloud Analytics And Mobile

Authors: John Campbell, Chris Crone, Gareth Jones, Surekha Parekh, Jay Yothers

1st Edition

1583474013, 978-1583474013

More Books

Students also viewed these Databases questions

Question

=+19.4. Consider weak convergence in LP((0, 1], @, ).

Answered: 1 week ago

Question

Design a job advertisement.

Answered: 1 week ago