插入排序demo1

master
30980 2 years ago
parent 38a51bdcfa
commit 311f084ee6

@ -0,0 +1,18 @@
package com.never.basic;
public class InsertSort {
public void insertSort(int[] arr){
if(arr == null ||arr.length<2){
return;
}
int minIndex = 0;
for(int end = 1; end < arr.length; end ++){
minIndex = end;
while(minIndex>0 && arr[minIndex]<arr[minIndex-1]){
CommonUtil.swapIndex(arr,minIndex,minIndex-1);
minIndex--;
}
}
}
}

@ -10,7 +10,8 @@ public class SortDemo {
int[] arr = {11,2,5,3,6,13,7};
printArr(arr);
// new SelectSort().selectSort(arr);
new BubbleSort().bubbleSort(arr);
// new BubbleSort().bubbleSort(arr);
new InsertSort().insertSort(arr);
printArr(arr);
}

Loading…
Cancel
Save