insertsort.java
来自「企业培训过程中的记录,希望对找工作的朋友帮助.」· Java 代码 · 共 25 行
JAVA
25 行
public class InsertSort{
public static void insertSort(int[] a){
int i, j, temp;
int n = a.length;
for(i = 0; i < n - 1; i ++){
temp = a[i + 1];
j = i;
while(j > -1 && temp <= a[j]){
a[j + 1] = a[j];
j --;
}
a[j + 1] = temp;
}
}
public static void main(String[] args){
int[] test = {64, 5, 7, 89, 6, 24};
int n = test.length;
insertSort(test);
for(int i = 0; i < n; i ++)
System.out.print(test[i] + " ");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?