选择排序
概述
选择的升序排列
代码
package com.lilei.myes.es.pack1114; import java.util.Random; public class choose_sort { public static void main(String[] args) { Random rand = new Random(); int[] array = new int[10]; for (int i = 0; i < array.length; i++) array[i] = rand.nextInt(100); for (int v : array) System.out.print(v + ","); System.out.println(); sort(array); for (int v : array) System.out.print(v + ","); } static void sort(int[] array) { for (int i = array.length - 1; i >= 1; i--) { int value = array[i]; int p = i; for (int j = 0; j < i; j++) { if (array[j] > value) { p = j; value = array[j]; } } if (p != i) { int tmp = array[i]; array[i] = array[p]; array[p] = tmp; } } } }