-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathQuick_Sort.java
More file actions
34 lines (28 loc) · 817 Bytes
/
Copy pathQuick_Sort.java
File metadata and controls
34 lines (28 loc) · 817 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
package Algorithms_Code.Java;
public class Quick_Sort {
int partition (int a[], int start, int end) {
int pivot = a[end];
int i = (start - 1);
for (int j = start; j <= end - 1; j++) {
if (a[j] < pivot){
i++;
int t = a[i];
a[i] = a[j];
a[j] = t;
}
}
int t = a[i + 1];
a[i + 1] = a[end];
a[end] = t;
return (i + 1);
}
void quick_sort(int a[], int start, int end){
if (start < end) {
int p = partition(a, start, end);
quick_sort(a, start, p - 1);
quick_sort(a, p + 1, end);
}
}
public static void main(String args[]){
}
}