Skip to content

Commit 6d38434

Browse files
author
weizhaoquan
committed
插入排序
1 parent 6dbdcd6 commit 6d38434

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package cn.byhieg.arithmetic.sort;
2+
3+
/**
4+
* Created by weizhaoquan on 2019/05/29.
5+
* 二分查找型
6+
*/
7+
public class dichotomyInsertSort {
8+
static void insertSort(int[] arr){
9+
for (int i = 1;i<arr.length;i++ ) {
10+
int key = arr[i];
11+
int L= 0,R=i-1;
12+
while(L<=R){
13+
int mid= L+(R-L)/2;
14+
if (arr[mid]>key) {
15+
R= mid-1;
16+
}else{
17+
L=mid+1;
18+
}
19+
}
20+
for (int j = i-1;j>=L;j--) {
21+
arr[j+1] =arr[j];
22+
arr[L]=key;
23+
}
24+
}
25+
}
26+
public static void main(String[] args){
27+
int[] arr = {6,3,5,7,3,7,8,9,1};
28+
insertSort(arr);
29+
System.out.printf( "1排序后的数组为 :" );
30+
for (int num:arr) {
31+
System.out.printf(" "+num);
32+
}
33+
34+
}
35+
}

0 commit comments

Comments
 (0)