很久没写排序算法,然后看了下算法视频,想写个基础的插入排序,并入归并,都写了十几分钟
有时候不经常去练习 总是会生疏的
package ZuoStudy;
public class insert_sort {
public static void main(String[] arg){
int[] name = {1,3,10,2,5};
insert_sort(0, name.length,name);
for (int i:name
) {
System.out.println(i);
}
}
public static void insert_sort(int begin,int end,int [] arrray){
for (int i = begin+1; i < end; i++) {
int temp = arrray[i];
int index = i;
for (int j = i-1; j >=0 ; j--) {
if (arrray[j]>temp){
arrray[j+1] = arrray[j];
}else {
arrray[j+1] = temp;
break;
}
}
}
}
}
多练练 写写