class SelectSort
{
public static void main(String[] args)
{
System.out.println("选择排序前的数组是:");
int[] arr = {26,26,0,48,26,1584,6,3};
for(int a:arr)
{
System.out.print(a+" ");
}
sort(arr);
System.out.println();
System.out.println("选择排序后的数组是:");
for(int a:arr)
{
System.out.print(a+" ");
}
}
public static void sort(int[] a)
{
for(int i =0;i<a.length-1;i++)
{
int point= i;
for(int j=i+1;j<a.length;j++)
{
if(a[point]>a[j])
{
point = j;
}
}
if(point!=i)
{
int num = a[point];
a[point] = a[i];
a[i] = num;
}
}
}
} |
|