Tuesday, February 21, 2023
HomeSoftware DevelopmentType the Matrix based mostly on the given column quantity

# Type the Matrix based mostly on the given column quantity

`#embody <bits/stdc++.h>`

`utilizing` `namespace` `std;`

`vector<vector<``int``> >`

`sortTheMatrix(vector<vector<``int``> >& matrix, ``int` `okay)`

`{`

` `

`    `

`    ``int` `n = matrix.dimension();`

` `

`    ``vector<pair<``int``, ``int``> > v;`

`    ``for` `(``int` `i = 0; i < n; i++) {`

` `

`        `

`        `

`        ``v.push_back({ matrix[i][k], i });`

`    ``}`

` `

`    `

`    `

`    ``kind(v.start(), v.finish());`

` `

`    `

`    `

`    ``reverse(v.start(), v.finish());`

` `

`    ``vector<vector<``int``> > a;`

`    ``for` `(``auto``& it : v) {`

`        ``a.push_back(`

` `

`            `

`            `

`            `

`            `

`            ``matrix[it.second]);`

`    ``}`

`    ``return` `a;`

`}`

` `

`void` `print(vector<vector<``int``> > matrix, ``int` `okay)`

`{`

`    ``vector<vector<``int``> > ans = sortTheMatrix(matrix, okay);`

`    ``cout << ``"Sorted Matrix Based mostly on column 2 Values :"`

`         ``<< endl;`

`    ``int` `N = ans.dimension();`

`    ``int` `M = ans[0].dimension();`

`    ``for` `(``int` `i = 0; i < N; i++) {`

`        ``for` `(``int` `j = 0; j < M; j++) {`

` `

`            ``cout << ans[i][j] << ``" "``;`

`        ``}`

`        ``cout << ``'n'``;`

`    ``}`

`}`

` `

`int` `predominant()`

`{`

`    ``vector<vector<``int``> > matrix = { { 10, 6, 9, 1 },`

`                                    ``{ 7, 5, 11, 2 },`

`                                    ``{ 4, 8, 3, 15 } };`

`    ``int` `Ok = 2;`

` `

`    `

`    ``print(matrix, Ok);`

`    ``return` `0;`

`}`

RELATED ARTICLES