国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > Java > 正文

Java數(shù)據(jù)結(jié)構(gòu)及算法實(shí)例:選擇排序 Selection Sort

2019-11-26 15:08:02
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
/**  * 選擇排序的思想:  * 每次從待排序列中找到最小的元素,  * 然后將其放到待排的序列的最左邊,直到所有元素有序  *   * 選擇排序改進(jìn)了冒泡排序,將交換次數(shù)從O(N^2)減少到O(N)  * 不過(guò)比較次數(shù)還是O(N)  */ package al; public class SelectSort {      public static void main(String[] args) {          SelectSort selectSort = new SelectSort();     int[] elements = { 14, 77, 21, 9, 10, 50, 43, 14 };     // sort the array     selectSort.sort(elements);     // print the sorted array     for (int i = 0; i < elements.length; i++) {       System.out.print(elements[i]);       System.out.print(" ");     }   }      /**    * @author    * @param array 待排數(shù)組    */   public void sort(int[] array) {     // min to save the minimum element for each round     int min, tmp;          for(int i=0; i<array.length; i++) {       min = i;       // search for the minimum element       for(int j=i; j<array.length; j++) {         if(array[j] < array[min]) {           min = j;         }               }       // swap minimum element       tmp = array[i];       array[i] = array[min];       array[min] = tmp;           }   } } 

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 洛宁县| 济宁市| 奉节县| 淅川县| 乐都县| 弥勒县| 丹巴县| 河东区| 永修县| 信宜市| 金堂县| 个旧市| 南郑县| 宁陕县| 尚义县| 东海县| 方城县| 策勒县| 廉江市| 缙云县| 东乡族自治县| 平阳县| 青冈县| 灵台县| 瑞金市| 凯里市| 厦门市| 石屏县| 巧家县| 离岛区| 临城县| 罗田县| 淳化县| 榆林市| 会昌县| 内乡县| 奉化市| 石阡县| 焉耆| 寿阳县| 桐柏县|