<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 選擇排序 SelectSort * 空間復雜度:O(1) * 時間復雜度:O(n2) ## 思路描述 每一次選擇數組中最小的值,放到最左邊 ![](https://box.kancloud.cn/44be35da53ae9ee564ce444542a43d10_811x248.gif) ## 例子 ``` old:[13, 7, 4, 6, 9, 24, 12, 3, 5, 2] select=2,swap 2 to 13 0)[2, 7, 4, 6, 9, 24, 12, 3, 5, 13] select=3,swap 3 to 7 1)[2, 3, 4, 6, 9, 24, 12, 7, 5, 13] select=5,swap 5 to 6 3)[2, 3, 4, 5, 9, 24, 12, 7, 6, 13] select=6,swap 6 to 9 4)[2, 3, 4, 5, 6, 24, 12, 7, 9, 13] select=7,swap 7 to 24 5)[2, 3, 4, 5, 6, 7, 12, 24, 9, 13] select=9,swap 9 to 12 6)[2, 3, 4, 5, 6, 7, 9, 24, 12, 13] select=12,swap 12 to 24 7)[2, 3, 4, 5, 6, 7, 9, 12, 24, 13] select=13,swap 13 to 24 8)[2, 3, 4, 5, 6, 7, 9, 12, 13, 24] result:[2, 3, 4, 5, 6, 7, 9, 12, 13, 24] ``` ## java實現 ~~~ public class SelectSort { public static void main(String[] args) { int[] nums = {13,7,4,6,9,24,12,3,5,2}; System.out.println("old:"+ Arrays.toString(nums)); System.out.println("result:"+Arrays.toString(sort(nums))); } // 選擇排序 public static int[] sort(int[] nums){ int select = 0; for(int i=0;i<nums.length;i++){ select = i; for(int j=i;j<nums.length;j++){ if(nums[j]<nums[select]){ select = j; } } if(select != i) { System.out.println("select="+nums[select]+",swap "+nums[select]+" to "+ nums[i]); swap(nums, i, select); System.out.println(i + ")" + Arrays.toString(nums)); } } return nums; } // 交換數組下標 public static void swap(int[] nums,int i,int j){ int temp = nums[i]; nums[i] = nums[j]; nums[j] = temp; } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看