冲压加工瑞安有做网站吗,网盘搜索 网站开发,1688阿里巴巴首页,商品房合同备案查询插入排序 基本思想 #xff1a;代码实现 基本思想 #xff1a;
实现数组从小到大排从第二个数开始跟前面的数比较 找到合适的位置插入 后面的数往后推移 但推移不会超过原来插入的数的下标
代码实现
public static void InsertSort(int[] arr) {for(int i 1;iarr.len… 插入排序 基本思想 代码实现 基本思想
实现数组从小到大排从第二个数开始跟前面的数比较 找到合适的位置插入 后面的数往后推移 但推移不会超过原来插入的数的下标
代码实现
public static void InsertSort(int[] arr) {for(int i 1;iarr.length;i) {//从1开始是因为要和前面的数有一个比较的过程int InsertIndexi-1;//要插入的理想目的地int Insertvalue arr[i];while (InsertIndex0Insertvaluearr[InsertIndex]) {//insertindex后移动一位arr[InsertIndex1]arr[InsertIndex];InsertIndex--;//一直在减去所以while结束后代表找到//后面要加还给他代表找到的那个位置}//if(InsertIndex1!i) {//1代表找的那个位置arr[Insertvalue1]Insertvalue;}}for(int i 0;iarr.length;i) {System.out.print(arr[i]\t);}}