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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # 編寫程序以反轉數組或字符串 > 原文: [https://www.geeksforgeeks.org/write-a-program-to-reverse-an-array-or-string/](https://www.geeksforgeeks.org/write-a-program-to-reverse-an-array-or-string/) 給定一個數組(或字符串),任務是反轉數組/字符串。 **示例**: ``` Input : arr[] = {1, 2, 3} Output : arr[] = {3, 2, 1} Input : arr[] = {4, 5, 1, 2} Output : arr[] = {2, 1, 5, 4} ``` **迭代方式**: > 1)將開始和結束索引初始化為`start = 0`,`end = n-1` > 2)在循環中,將`arr[start]`與`arr[end]`交換,并如下更改開始和結束: > `start = start + 1`,`end = end – 1` ![reverse-a-number](https://img.kancloud.cn/b3/bb/b3bbef4e0c8bcc8cd206119256e0a32a_365x302.png) 另一個反轉字符串的示例: ![reverse-a-string](https://img.kancloud.cn/5d/94/5d945e9863457e2b64fbd729e9f8ef23_250x279.png) 下面是上述方法的實現: ## C++ ```cpp // Iterative C++ program to reverse an array #include <bits/stdc++.h> using namespace std; /* Function to reverse arr[] from start to end*/ void rvereseArray(int arr[], int start, int end) { ????while (start < end) ????{ ????????int temp = arr[start];? ????????arr[start] = arr[end]; ????????arr[end] = temp; ????????start++; ????????end--; ????}? }????? /* Utility function to print an array */ void printArray(int arr[], int size) { ???for (int i = 0; i < size; i++) ???cout << arr[i] << " "; ???cout << endl; }? /* Driver function to test above functions */ int main()? { ????int arr[] = {1, 2, 3, 4, 5, 6}; ????int n = sizeof(arr) / sizeof(arr[0]);? ????// To print original array? ????printArray(arr, n); ????// Function calling ????rvereseArray(arr, 0, n-1); ????cout << "Reversed array is" << endl; ????// To print the Reversed array ????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>

                              哎呀哎呀视频在线观看