<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國際加速解決方案。 廣告
                # 數組右旋轉的逆向算法 > 原文: [https://www.geeksforgeeks.org/reversal-algorithm-right-rotation-array/](https://www.geeksforgeeks.org/reversal-algorithm-right-rotation-array/) 給定一個數組,將其右旋轉 k 個元素。 ![](https://img.kancloud.cn/07/ed/07edb97a3fd73f5b6d90e7d8580af38a_436x74.png) 在`K = 3`旋轉后 ![](https://img.kancloud.cn/7b/a1/7ba1163b3e095fd47cebce3969637fc9_442x93.png) **示例**: ``` Input: arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} k = 3 Output: 8 9 10 1 2 3 4 5 6 7 Input: arr[] = {121, 232, 33, 43 ,5} k = 2 Output: 43 5 121 232 33 ``` **注意**:在下面的解決方案中,假定 k 小于或等于 n。 我們可以通過修改`k = k % n`來輕松修改解決方案以處理更大的 k 值 **算法**: ``` rotate(arr[], d, n) reverseArray(arr[], 0, n-1) ; reverse(arr[], 0, d-1); reverse(arr[], d, n-1); ``` 下面是上述方法的實現: ## C++ ```cpp // C++ program for right rotation of? // an array (Reversal Algorithm) #include <bits/stdc++.h> /*Function to reverse arr[]? from index start to end*/ void reverseArray(int arr[], int start, ????????????????????????????int end) { ????while (start < end) ????{ ????????std::swap(arr[start], arr[end]); ????????start++; ????????end--; ????} } /* Function to right rotate arr[] of size n by d */ void rightRotate(int arr[], int d, int n) { ????reverseArray(arr, 0, n-1); ????reverseArray(arr, 0, d-1); ????reverseArray(arr, d, n-1); } /* function to print an array */ void printArray(int arr[], int size) { ????for (int i = 0; i < size; i++) ????????std::cout << arr[i] << " "; } // driver code int main() { ????int arr[] = {1, 2, 3, 4, 5,? ????????????????6, 7, 8, 9, 10}; ????int n = sizeof(arr)/sizeof(arr[0]); ????int k = 3; ????rightRotate(arr, k, n); ????printArray(arr, n); ????return 0; }? ```
                  <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>

                              哎呀哎呀视频在线观看