选择排序

/**
 * Created by xuxiaoyu on 2015/6/25.
 */
//选择排序:比如在一个长度为N的无序数组中,在第一趟遍历N个数据,找出其中最小的数值与第一个元素交换,
//第二趟遍历剩下的N-1个数据,找出其中最小的数值与第二个元素交换......第N-1趟遍历剩下的2个数据,
//找出其中最小的数值与第N-1个元素交换,至此选择排序完成
public class SelectionSort {

    public static void main(String[] args) {
        int a[] = { 2, 5, 8, 3, 2, 9, 7, 6, 1, 4,3333,22 };
        int temp;
        for (int i = 0; i < a.length; i++)
            for (int j = i + 1; j < a.length; j++) {
                if (a[i] > a[j]) {
                    temp = a[j];
                    a[j] = a[i];
                    a[i] = temp;
                }
            }
        for (int k = 0; k < a.length; k++)
            System.out.print(a[k] + "、");
    }

}
原文地址:https://www.cnblogs.com/xxyBlogs/p/4604029.html