import javax.print.attribute.standard.MediaSize.Other;
public class Sort {
public static void main(String[] args) {
int[] arr = new int[] { 9, 8, 7, 5, 6, 4, 2, 3, 0, 1,11 };
int[] other = new int[arr.length];
int count = 1; // count用来统计新数列中的元素个数
boolean flag = true;
other[0] = arr[0]; // 向新数列中先存放一个
for(int i=1; i<arr.length; i++){
for(int j=0; j<count; j++){
// 如果arr[i]大于other[j]的话,就继续向后比较,如果不是插入数据,如果比所有的数据都大
if(arr[i]>other[j] && j!=(count-1)){
continue;
}else if(flag){
insert(j, other, arr[i]);
flag = false; // 如果这里插入成功的话,后面的数据就不用再逐一比较
}
}
flag = true;
count++;
}
print(other);
}
/**
* 插入新数据
* @param pos 插入位置
* @param other 插入数组
* @param value 插入的值
*/
public static void insert(int pos, int[] other, int value){
for(int i=other.length-1; i>pos; i--){
other[i] = other[i-1];
}
other[pos] = value;
}
/**
* 打印数组
*/
public static void print(int[] other){
for(int x=0; x<other.length; x++){
System.out.println(other[x]);
}
}
}