<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                # 對幾乎排序(或 K 排序)的數組進行排序 > 原文: [https://www.geeksforgeeks.org/nearly-sorted-algorithm/](https://www.geeksforgeeks.org/nearly-sorted-algorithm/) 給定 n 個元素的數組,其中每個元素距離其目標位置最多 k 個,設計一種算法,以 O(n log k)時間排序。 例如,讓我們考慮 k 為 2,在排序數組中索引 7 處的元素可以在給定數組中索引 5、6、7、8、9 處。 **示例**: ``` Input : arr[] = {6, 5, 3, 2, 8, 10, 9} k = 3 Output : arr[] = {2, 3, 5, 6, 8, 9, 10} Input : arr[] = {10, 9, 8, 7, 4, 70, 60, 50} k = 4 Output : arr[] = {4, 7, 8, 9, 10, 50, 60, 70} ``` 我們可以**使用插入排序**對元素進行有效排序。 以下是標準插入排序的 C 代碼。 ## C ``` /* Function to sort an array using insertion sort*/ void insertionSort(int A[], int size) { ???int i, key, j; ???for (i = 1; i < size; i++) ???{ ???????key = A[i]; ???????j = i-1; ???????/* Move elements of A[0..i-1], that are greater than key, to one? ??????????position ahead of their current position. ??????????This loop will run at most k times */ ???????while (j >= 0 && A[j] > key) ???????{ ???????????A[j+1] = A[j]; ???????????j = j-1; ???????} ???????A[j+1] = key; ???} } ```
                  <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>

                              哎呀哎呀视频在线观看