File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ package com .gatsby .utils ;
2
+
3
+ /**
4
+ * @ClassName: SortUtil
5
+ * @Description: 排序类
6
+ * @author: Gatsby
7
+ * @date: 2022/7/25 15:03
8
+ */
9
+
10
+ public class SortUtil {
11
+ /**
12
+ * @MethodName: quickSort
13
+ * @Parameter: [nums, begin, end]
14
+ * @Return void
15
+ * @Description: 快速排序
16
+ * @author: Gatsby
17
+ * @date: 2022/7/25 15:20
18
+ */
19
+ public static void quickSort (int [] nums , int begin , int end ) {
20
+ if (begin < end ) {
21
+ int pivot = nums [begin ];
22
+ int i = begin ;
23
+ int j = end ;
24
+ while (i < j ) {
25
+ while (i < j && nums [j ] > pivot ) {
26
+ j --;
27
+ }
28
+ if (i < j ) {
29
+ nums [i ] = nums [j ];
30
+ i ++;
31
+ }
32
+
33
+ while (i < j && nums [i ] < pivot ) {
34
+ i ++;
35
+ }
36
+ if (i < j ) {
37
+ nums [j ] = nums [i ];
38
+ j --;
39
+ }
40
+ }
41
+ nums [j ] = pivot ;
42
+ quickSort (nums , begin , j - 1 );
43
+ quickSort (nums , j + 1 , end );
44
+ }
45
+ }
46
+ }
47
+
48
+
You can’t perform that action at this time.
0 commit comments