插入排序

import java.util.Arrays;

public class Main {
public static void main(String []args)
{
int []a={3,1,6,0,-8,6,3,5,9,4};
ChaRu(a);
System.out.println(Arrays.toString(a));
}
public static void ChaRu(int []a)
{
ChaRu1(a,1);
}
public static void ChaRu1(int []a,int low)
{
if(low==a.length)
{
return;
}
int t=a[low];
int i=low-1;
while(i>=0&&t<a[i])
{
a[i+1]=a[i];
i--;
}
if(i+1!=low)
{
a[i+1]=t;
}
ChaRu1(a,low+1);
}
}
posted @ 2024-02-17 22:19  赵千万  阅读(2)  评论(0编辑  收藏  举报