parent
15112ddb05
commit
2906c009b4
@ -0,0 +1,20 @@
|
|||||||
|
public class InsertionSort
|
||||||
|
{
|
||||||
|
private static void exch(in[]a,int i,int j)
|
||||||
|
{
|
||||||
|
int t=a[i];
|
||||||
|
a[i]=a[j];
|
||||||
|
a[j]=t;
|
||||||
|
}
|
||||||
|
public void sort(int[]a)
|
||||||
|
{
|
||||||
|
int N=a.length;
|
||||||
|
for(int i=1;i<N;i++)
|
||||||
|
{
|
||||||
|
for(int j=i;j>0&&a[j]<a[j-1];j--)
|
||||||
|
{
|
||||||
|
exch(a,j,j-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue