插入排序
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);
}
}
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);
}
}
本文来自博客园,作者:赵千万,转载请注明原文链接:https://www.cnblogs.com/zhaoqianwan/p/17891914.html
千万千万赵千万