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
43 lines (36 loc) Β· 950 Bytes

File metadata and controls

43 lines (36 loc) Β· 950 Bytes
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
43
package sorting;
import java.util.Arrays;
public class QuickSort {
public static void quickSort(int[] arr) {
quickSort(arr, 0, arr.length - 1);
}
private static void quickSort(int[] arr, int start, int end) {
if (start >= end)
return;
int pivotIndex = partition(arr, start, end);
quickSort(arr, start, pivotIndex - 1);
quickSort(arr, pivotIndex + 1, end);
}
private static int partition(int[] arr, int start, int end) {
int pivot = arr[end];
int pivotIndex = start;
for (int i = start; i < end; i++) {
if (arr[i] < pivot) {
swap(arr, pivotIndex, i);
pivotIndex++;
}
}
swap(arr, pivotIndex, end);
return pivotIndex;
}
private static void swap(int[] arr, int i, int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void main(String[] args) {
int[] arr = { 5, 3, -13, 2, 0, -1, 32, 6984, 8, -1, 3 };
quickSort(arr);
System.out.println(Arrays.toString(arr));
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.