{
//交换排序之--最简单的冒泡排序法
public static void BubbleSort(int[] a)
{
int i,j,temp;
int n = a.length;
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if (a[i]>a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
//插入排序-- 直接插入排序
public static void InsertSort(int[] a)
{
int i,j,temp;
int n = a.length;
for(i=1;i<n;i++)
{
temp = a[i];
j=i-1;
while((a[j]>temp)&&(j>=0))
{
a[j+1] = a[j];
j--;
}
a[j+1] = temp;
}
}
//选择排序
public static void SelectSort(int[] a)
{
int i,j,min,temp;
int n=a.length;
for(i=0;i<n;i++)
{
min = a[i];
for(j=i+1;j<n;j++)
{
if(a[j]<min)
{
temp = min;
min =a[j];
a[j] = temp;
}
}
a[i] =min ;
}
}
public static void main(String[] args)
{
int[] arr = {45,76,32,32,5,4,54,7,943,3};
int n = arr.length;
BubbleSort(arr);
for(int i=0;i<n;i++)
System.out.print(arr[i]+“ ”);
System.out.println();
InsertSort(arr);
for(int i=0;i<n;i++)
System.out.print(arr[i]+“ ”);
System.out.println();
SelectSort(arr);
for(int i=0;i<n;i++)
System.out.print(arr[i]+“ ”);
}
}