package m;
import java.util.*;
public class b {
public static int[]a={2,34,14,56,78,97,90,13,11,45};
public static void main(String[]args)
{
chooseSort(10);
System.out.println("the result is:");
for(int t=0;t<10;t++)
System.out.print(a[t]+" ");
}
public static void chooseSort(int n)
{
int i,j;
int min=32767;
int temp;
int index = 0;
for(i=0;i<n-1;i++)//n-1
{
index=i;
for(j=i+1;j<n;j++)//每趟比较的次数
{
if(a[j]<a[index])//记下笑的下标
{
index=j;
if(index!=i)
{
temp=a[i];
a[i]=a[index];
a[index]=temp;
}
}
}
System.out.println("current sorting:");
for(int k=0;k<n;k++)
System.out.print(a[k]+" ");
System.out.println("");
}
}
}
本文出自 “hagar” 博客,谢绝转载!