/**
* 选择排序,是很无脑的排序,就是两两比大小,然后交换。。。
* @author 王嘉锐
*
*/
public class SelectSort {
public static void selectSort(int[] source){
for(int i = 0; i < source.length; i++){
for(int j = 0; j < source.length; j++){
if( source[i] < source[j]){
swap(source, i, j);
}
}
}
}
public static void swap(int source[], int x, int y){
int temp = source[x];
source[x] = source[y];
source[y] = temp;
}
public static void main(String[] args) {
int[] a = {1,5,2,7,3,8,10};
selectSort(a);
for(int i = 0; i < a.length; i++){
System.out.println(a[i]);
}
}
}
选择排序
最新推荐文章于 2024-08-04 11:07:52 发布