public class Mytest{
public static void main(String[]args){
int []arr={9,-4,6,-100};
insertSort(arr);
System.out.println(Arrays.toString(arr));
}
public static void insertSort(int []arr){
for (int i=1;i<arr.length;i++){
int temp=arr[i];
int j;
for ( j=i;j>0&&temp<arr[j-1];j--){
arr[j]=arr[j-1];
}
arr[j]=temp;
}
}
}
来源:CSDN
作者:xiaohanguo_xiao
链接:https://blog.csdn.net/xiaohanguo_xiao/article/details/104582107