-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSort.java
More file actions
42 lines (26 loc) · 739 Bytes
/
QuickSort.java
File metadata and controls
42 lines (26 loc) · 739 Bytes
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 com.company;
import java.util.Arrays;
public class QuickSort {
public void sort(int [] n){
sort(n,0,n.length-1);
}
public void sort(int [] n, int left, int right) {
if (left < right) {
int pivot = n[right];
int cnt = left;
for (int i = left; i < right; i++) {
if (n[i] <= pivot) {
int holder = n[cnt];
n[cnt] = n[i];
n[i] = holder;
cnt++;
}
}
int holder = n[cnt];
n[cnt] = n[right];
n[right] = holder;
sort(n, left, cnt - 1);
sort(n, cnt+1, right);
}
}
}