package org.select;
public class SelectSort {
public static void main(String[] args) {
int a[] = {64,5,7,89,6,24};
System.out.print("排序之前:");
for(int i = 0;i<a.length;i++){
System.out.print(a[i]+" ");
}
sort(a);
System.out.print("\n排序之后:");
for(int i = 0;i<a.length;i++){
System.out.print(a[i]+" ");
}
}
public static void sort(int a[]){
int small,temp;
for(int i = 0;i<a.length;i++){
small = i;
for(int j = i+1;j<a.length;j++){
if(a[j]<a[small]){
small = j;
}
}
if(small != i){
temp = a[i];
a[i] = a[small];
a[small] = temp;
}
}
}
}
public class SelectSort {
public static void main(String[] args) {
int a[] = {64,5,7,89,6,24};
System.out.print("排序之前:");
for(int i = 0;i<a.length;i++){
System.out.print(a[i]+" ");
}
sort(a);
System.out.print("\n排序之后:");
for(int i = 0;i<a.length;i++){
System.out.print(a[i]+" ");
}
}
public static void sort(int a[]){
int small,temp;
for(int i = 0;i<a.length;i++){
small = i;
for(int j = i+1;j<a.length;j++){
if(a[j]<a[small]){
small = j;
}
}
if(small != i){
temp = a[i];
a[i] = a[small];
a[small] = temp;
}
}
}
}