File tree Expand file tree Collapse file tree 1 file changed +2
-21
lines changed
src/com/fantasy/algorithm/sort Expand file tree Collapse file tree 1 file changed +2
-21
lines changed Original file line number Diff line number Diff line change 1717 *
1818 * <pre>
1919 * author : Fantasy
20- * version : 1.0 , 2020-08-31
20+ * version : 1.1 , 2020-09-03
2121 * since : 1.0, 2020-08-31
2222 * </pre>
2323 */
@@ -36,27 +36,8 @@ public static void insertionSort(int[] arr) {
3636 int j ;
3737 for (int i = 1 ; i < length ; i ++) {
3838 value = arr [i ];
39- for (j = i - 1 ; j >= 0 && arr [j ] > value ; j --) {
40- arr [j + 1 ] = arr [j ];
41- }
42- arr [j + 1 ] = value ;
43- }
44- }
45-
46- /**
47- * 插入排序的另一种实现
48- *
49- * @param arr 数组
50- */
51- public static void insertionSort2 (int [] arr ) {
52- int length = arr .length ;
53- int value ; // 待插入的值
54- for (int i = 1 ; i < length ; i ++) {
55- value = arr [i ];
56- int j = i ;
57- while (j > 0 && arr [j - 1 ] > value ) {
39+ for (j = i ; j >= 1 && arr [j - 1 ] > value ; j --) {
5840 arr [j ] = arr [j - 1 ];
59- j --;
6041 }
6142 arr [j ] = value ;
6243 }
You can’t perform that action at this time.
0 commit comments