国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 新竹市| 文水县| 黄骅市| 澜沧| 中超| 措美县| 永城市| 唐海县| 思南县| 年辖:市辖区| 宁河县| 福泉市| 离岛区| 新乡县| 大余县| 芮城县| 昌乐县| 耿马| 伊宁县| 洮南市| 岗巴县| 西平县| 崇文区| 响水县| 南漳县| 黎川县| 仁化县| 松阳县| 古蔺县| 内丘县| 开鲁县| 饶平县| 黑河市| 洪洞县| 岱山县| 安溪县| 蓬莱市| 隆子县| 四平市| 凌海市| 迁安市|