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--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue