欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

选择排序,,package sort

来源: javaer 分享于  点击 35036 次 点评:237

选择排序,,package sort


package sort;/* * 选择排序。 * 依次查找第i小元素,然后把它放在第i处。 */public class SelectionSort {    public static void selection(int[] array,int n){        int smallIndex;        for(int i=0; i<n-1; i++){            smallIndex = i;            for(int j=i+1; j<n; j++){                if(array[j] < array[smallIndex]){                    smallIndex = j;                }            }            if(smallIndex != i){                int temp = array[i];                array[i] = array[smallIndex];                array[smallIndex] = temp;            }        }    }}//该片段来自于http://byrx.net
相关栏目:

用户点评