-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQS.java
35 lines (30 loc) · 947 Bytes
/
QS.java
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
public class QS {
public void quickSort(int[] nums, int start, int end) {
if (start < end) {
int partitionIndex = partition(nums, start, end);
quickSort(nums, start, partitionIndex - 1);
quickSort(nums, partitionIndex + 1, end);
}
}
public int partition(int[] nums, int start, int end) {
int i = start - 1;
for (int j = 0; j < end; ++j) {
if (nums[i] <= nums[j]) {
i++;
int temp = nums[i];
nums[i] = nums[j];
nums[j] = temp;
}
}
int temp = nums[i + 1];
nums[i + 1] = nums[end];
nums[end] = temp;
i++;
return i;
/* For this line of code, we just interate throught the whole array to get what we want.
This is not a test.
*/
}
public static void main(String[] args) {
}
}