选择排序 排序动画
import java.util.Arrays;
/**
* 选择排序
* @author baoy
*
*/
public class SelectionSort {
public static void main(String[] args) {
int []a = {49,38,65,97,76,13,27,14,10};
sort(a);
System.out.println(Arrays.toString(a));
}
public static void sort(int [] a){
for (int i = 0; i < a.length; i++) {
int temp = i;
for (int j = i+1; j < a.length; j++) {
if (a[temp] > a[j]) {
temp = j;
}
}
if (temp != i)
swap(a, i, temp);
}
}
public static int[] swap(int[] a, int i, int j) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
return a;
}
}
捐助开发者
在兴趣的驱动下,写一个免费
的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(支持支付宝和微信 以及扣扣群),没钱捧个人场,谢谢各位。
个人主页:http://knight-black-bob.iteye.com/
谢谢您的赞助,我会做的更好!