Select a sort basic idea: Select a minimum element from all elements a[i] in a[0] (that is, let the smallest element a[i] and a[0] exchange), as the first round, the second round is from the beginning of the a[1] to the final elements of the selection of a minimum element, placed in the a[1]; In turn. n the number of (n-1) wheels to be carried out. The number of comparisons is as much as the bubbling method, but only one exchange in each round is less than that of bubbling, which is efficient compared to the bubbling method.
/** * */package com.zimo.algorithm;/** * @author Sub-ink * * 2015-3-4 PM 10:51:32 */public class Selectsort {/** * @param arg s */public static void Main (string[] args) {int[] data={25,15,42,16,12,36};selectsort (data); for (int i = 0; i < Data.le Ngth; i++) {System.out.println (data[i]);}} /** * Select sort * @param data */private static void Selectsort (int[] data) {int temp;int min;for (int i = 0; i < data.length ; i++) {min = i;for (int j = i+1; J < Data.length; J + +) {if (Data[min] > Data[j]) {min=j;}} temp = Data[i];d ata[i] = Data[min];d ata[min] = temp;}}}
Selection and sorting of algorithms