/*
 * 选择排序:1、每次i循环,总是拿第i位的数字与后面的数字一一比较,取出最小的数字放置第i位
 *         2、第一次i循环之后,遍历出最小的数字放置第一位
 */
public class selectsort {
    public static void main(String args[]) {
        int array[] = { 3, 3, 4, 1, 9, 8, 7, 2, 6, 5, 6, 10, 2, 1 };
        int temp;
        int size = array.length;
        for (int i = 0; i < size - 1; i++) {
            for (int j = i + 1; j < size; j++)
                if (array[i] > array[j]) {
                    temp = array[j];
                    array[j] = array[i];
                    array[i] = temp;
                }
        }
        for (int i = 0; i < size; i++) {
            System.out.println(array[i]);
        }
    }
}

运行结果:
1 1 2 2 3 3 4 5 6 6 7 8 9 10 

 

posted on 2016-07-26 15:41  Worms  阅读(168)  评论(0)    收藏  举报