<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/sorting-rows-matrix-ascending-order-followed-sorting-columns-descending-order/](https://www.geeksforgeeks.org/sorting-rows-matrix-ascending-order-followed-sorting-columns-descending-order/) 給定矩陣,以升序對矩陣的行進行排序,然后以降序對列進行排序。 **示例**: ``` Input : a[3][3] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; Output : 7 8 9 4 5 6 1 2 3 Input : a[3][3] = {{3, 2, 1}, {9, 8, 7}, {6, 5, 4}}; Output : 7 8 9 4 5 6 1 2 3 ``` 1)遍歷所有行,并使用簡單數組排序以升序對行進行排序。 2)將矩陣轉換為其[轉置](https://www.geeksforgeeks.org/c-program-find-transpose-matrix/) 3)再次對所有行進行排序,但是這次以升序排列。 4)再次將矩陣轉換為其[轉置的](https://www.geeksforgeeks.org/c-program-find-transpose-matrix/) ## C++ ```cpp // C++ implementation to sort the rows // of matrix in ascending order followed by // sorting the columns in descending order #include <bits/stdc++.h> using namespace std; #define MAX_SIZE 10 // function to sort each row of the matrix // according to the order specified by? // ascending. void sortByRow(int mat[][MAX_SIZE], int n,? ???????????????????????????bool ascending) { ????for (int i = 0; i < n; i++) ????{ ??????if (ascending)???? ????????sort(mat[i], mat[i] + n); ??????else ??????????sort(mat[i], mat[i] + n, greater<int>()); ????}?????? } // function to find transpose of the matrix void transpose(int mat[][MAX_SIZE], int n) { ????for (int i = 0; i < n; i++) ????????for (int j = i + 1; j < n; j++)? ????????????// swapping element at index (i, j)? ????????????// by element at index (j, i) ????????????swap(mat[i][j], mat[j][i]); } // function to sort the matrix row-wise // and column-wise void sortMatRowAndColWise(int mat[][MAX_SIZE], ???????????????????????????????????????int n) { ????// sort rows of mat[][] ????sortByRow(mat, n, true); ????// get transpose of mat[][] ????transpose(mat, n); ????// again sort rows of mat[][] in descending ????// order. ????sortByRow(mat, n, false); ????// again get transpose of mat[][] ????transpose(mat, n); } // function to print the matrix void printMat(int mat[][MAX_SIZE], int n) { ????for (int i = 0; i < n; i++) { ????????for (int j = 0; j < n; j++) ????????????cout << mat[i][j] << " "; ????????cout << endl; ????} } // Driver program to test above int main() { ????int n = 3; ????int mat[n][MAX_SIZE]? = {{3, 2, 1}, ????????????????????????????{9, 8, 7},? ????????????????????????????{6, 5, 4}}; ????cout << "Original Matrix:\n"; ????printMat(mat, n); ????sortMatRowAndColWise(mat, n); ????cout << "\nMatrix After Sorting:\n"; ????printMat(mat, 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>

                              哎呀哎呀视频在线观看