<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國際加速解決方案。 廣告
                # C 中的選擇排序程序 > 原文: [https://beginnersbook.com/2015/02/selection-sort-program-in-c/](https://beginnersbook.com/2015/02/selection-sort-program-in-c/) 在選擇排序中,最小元素與未排序元素列表的第一個元素交換(交換元素占用最初放置最小元素的位置)。然后,第二個最小元素與未排序元素列表的第二個元素交換,依此類推,直到所有元素都被排序。在下面的 C 程序中,我們實現了相同的邏輯。 在完成程序之前,讓我們通過一個例子來看看選擇排序的步驟: + 輸入的元素:22 0 -90 89 17 + 步驟 1:-90 0 22 89 17(22 和 -90 交換位置) + 步驟 2:-90 0 22 89 17(0 在正確位置,無需交換) + 步驟 3:-90 0 17 89 22(22 和 17 交換位置) + 步驟 4:-90 0 17 22 89(89 和 22 交換位置) #### C 程序 - 選擇排序 ```c #include<stdio.h> int main(){ /* Here i & j for loop counters, temp for swapping, * count for total number of elements, number[] to * store the input numbers in array. You can increase * or decrease the size of number array as per requirement */ int i, j, count, temp, number[25]; printf("How many numbers u are going to enter?: "); scanf("%d",&count); printf("Enter %d elements: ", count); // Loop to get the elements stored in array for(i=0;i<count;i++) scanf("%d",&number[i]); // Logic of selection sort algorithm for(i=0;i<count;i++){ for(j=i+1;j<count;j++){ if(number[i]>number[j]){ temp=number[i]; number[i]=number[j]; number[j]=temp; } } } printf("Sorted elements: "); for(i=0;i<count;i++) printf(" %d",number[i]); return 0; } ``` **輸出:** ![selection_sort_output_cmd](https://img.kancloud.cn/23/2f/232f543ee935b4bddfac7d70b69f6947_541x236.jpg) 正如您所看到的,我們已經按隨機順序輸入了 6 個元素,程序通過使用我們在程序中實現的選擇排序算法按升序對它們進行排序。您還可以修改此程序,以按降序對元素進行排序。
                  <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>

                              哎呀哎呀视频在线观看