package com.company;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] str = {1, 5, 36, 87, 54, 12, 65, 4, 2};
int i = 0,temp = 0;
int m = 1;
for (; m < str.length; m++) {
temp = str[m];
for(i = m - 1;i>=0;i--){
if(temp>str[i]){
break;
}
else {
str[i+1] = str[i];
}
}
str [i+1] = temp;
}
System.out.println(Arrays.toString(str));
}
// write your code here
}
Java插入排序法
最新推荐文章于 2022-10-15 10:12:46 发布