Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
42 lines (36 loc) · 1.07 KB

File metadata and controls

42 lines (36 loc) · 1.07 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package Sorting;
import java.util.Arrays;
public class quickSort {
/**
* Program to demonstrate quick sort
*/
public static void quickSort(int [] arr, int left, int right){
if(left < right){
int pivotIndex = partition(arr, left,right);
System.out.println(Arrays.toString(arr));
quickSort(arr, left, pivotIndex-1);
quickSort(arr, pivotIndex+1, right);
}
}
public static int partition(int [] arr, int left, int right){
int pivot = arr[right];
int i = left - 1;
for(int j=left;j< right;j++){
if(arr[j]<=pivot){
i++;
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
int temp = arr[i+1];
arr[i + 1] = arr[right];
arr[right] = temp;
return i + 1;
}
public static void main(String [] args){
int[] arr = {5, 2, 7, 3, 9, 1, 4, 6, 8};
quickSort(arr, 0, arr.length - 1);
System.out.println(Arrays.toString(arr));
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.