import org.junit.Test;
import java.util.Arrays;
/**
* Created by wc on 2018/4/28.
*/
public class 插入排序 {
@Test
public void test(){
int[] array={1,9,8,4,2,7,6,5};
sort(array);
System.out.print(Arrays.toString(array));
}
public void sort(int[] array){
for(int i=1;i<array.length;i++){
int j=i;
int target=array[i];
while(j>0&&target<array[j-1]){
array[j]=array[j-1];
j--;
}
array[j]=target;
}
}
}
网友评论