Sort a c++ program one and two and three dimensional array in ascending and descending order
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
vector< vector<int> > vect{{2, 5, 1},
{4, 6, 11},
{8, 2, 1}};
int m = vect.size();
int n = vect[0].size();
for (int i=0; i<m; i++)
{
for (int j=0; j<n ;j++)
cout << vect[i][j] << " ";
cout << endl;
}
sort(vect[0].begin(), vect[0].end());
for (int i=0; i<m; i++)
{
for (int j=0; j<n ;j++)
cout << vect[i][j] << " ";
cout << endl;
}
return 0;
}
Comments
Leave a comment