插入排序

来源:互联网 发布:属于网络层协议有哪些 编辑:程序博客网 时间:2024/06/08 09:26
public static void insertSort(int[] a){
if((a!=null)){
for(int i=1;i<a.length;i++){
int temp=a[i];
int j=i;
if(a[j-1]>temp){
while(j>=1&&a[j-1]>temp){
a[j]=a[j-1];
j--;
}
 }
a[j]=temp;
}
 }
}