- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickSort2.java
More file actions
Latest commit
34 lines (26 loc) · 589 Bytes
/
Copy pathquickSort2.java
File metadata and controls
34 lines (26 loc) · 589 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
packagesort;
publicclassquickSort2 {
publicvoidsort(intleft, intright, int[] arr){
if(left >= right)
return;
intpivot = left;
inti = left+1;
intj = right;
while(i < j){
while(i<j && arr[i] < arr[pivot]){i++;}
while(i<j && arr[j] > arr[pivot]){j--;}
if(i < j)
swap(arr, i, j);
}
inttmp = arr[pivot];
arr[pivot] = arr[i];
arr[i] = tmp;
sort(left, i, arr);
sort(i+1, right, arr);
}
publicvoidswap(int[] arr, inti, intj){
inttmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
}