Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 49e104e

Browse files
committed
快速排序
1 parent e5b4633 commit 49e104e

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

app/src/main/java/com/zhxh/codeproj/sortcode/QuickSort.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
package com.zhxh.codeproj.sortcode;
22

3-
public class QuickSort {
3+
import java.util.Arrays;
44

5+
public class QuickSort {
56
public static void main(String[] args) {
6-
int i;
77
int a[] = {1, 3, -2, 5, 4, -3, 2, 6, -1, 1};
8-
9-
System.out.printf("排序前:");
10-
for (i = 0; i < a.length; i++)
11-
System.out.printf("%d ", a[i]);
12-
System.out.printf("\n");
13-
8+
System.out.println("排序前:" + Arrays.toString(a));
149
quickSort(a, 0, a.length - 1);
15-
16-
System.out.printf("排序后:");
17-
for (i = 0; i < a.length; i++)
18-
System.out.printf("%d ", a[i]);
19-
System.out.printf("\n");
10+
System.out.println("排序后:" + Arrays.toString(a));
2011
}
21-
2212
/*
2313
* 快速排序
24-
*
2514
* 参数说明:
26-
* a -- 待排序的数组
27-
* l -- 数组的左边界(例如,从起始位置开始排序,则l=0)
28-
* r -- 数组的右边界(例如,排序截至到数组末尾,则r=a.length-1)
15+
* a -- 待排序的数组
16+
* l -- 数组的左边界(例如,从起始位置开始排序,则l=0)
17+
* r -- 数组的右边界(例如,排序截至到数组末尾,则r=a.length-1)
2918
*/
3019
public static void quickSort(int[] a, int l, int r) {
3120
if (l < r) {

0 commit comments

Comments
 (0)