File tree Expand file tree Collapse file tree 1 file changed +0
-52
lines changed Expand file tree Collapse file tree 1 file changed +0
-52
lines changed Original file line number Diff line number Diff line change @@ -17,58 +17,6 @@ public static void main(String[] args) {
17
17
}
18
18
19
19
20
- /**
21
- * 传统方法
22
- * 选择left为基准点
23
- *
24
- * @param array
25
- * @param left
26
- * @param right
27
- */
28
- public void quickSortLeftBase (int [] array , int left , int right ) {
29
- // 元素个数小于等于1,无需排序,结束
30
- if (left >= right ) {
31
- return ;
32
- }
33
-
34
- int index = getPartition (array , left , right );
35
- quickSortLeftBase (array , left , index - 1 );
36
- quickSortLeftBase (array , index + 1 , right );
37
- }
38
-
39
-
40
- /**
41
- * 传统方法
42
- * 选择left为基准点,设为base
43
- * 先从右边元素开始,找到第一个比base小的,将array[i]设为该值(array[j])。
44
- * 再从左边开始,找到第一个比base大的,将array[j]设为该值(array[i])。
45
- * 结束循环后,将array[i]的值设为base。
46
- *
47
- * @param array
48
- * @param left
49
- * @param right
50
- */
51
- private int getPartition (int [] array , int left , int right ) {
52
- int i = left , j = right ;
53
- int baseVal = array [left ];
54
-
55
- while (i < j ) {
56
- while (i < j && array [j ] >= baseVal ) {
57
- j --;
58
- }
59
- array [i ] = array [j ];
60
- while (i < j && array [i ] <= baseVal ) {
61
- i ++;
62
- }
63
- array [j ] = array [i ];
64
- }
65
-
66
- array [i ] = baseVal ;
67
- // i 为基准点坐标
68
- return i ;
69
- }
70
-
71
-
72
20
public void sort (int [] nums ) {
73
21
// 为了避免出现耗时的极端情况,先随机打乱
74
22
shuffle (nums );
You can’t perform that action at this time.
0 commit comments