sort a 2d vector c++ stl
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
std::vector<std::vector<int>> vec = {{3, 1, 4}, {1, 5, 9}, {2, 6, 5}};
// Sorting each row of the 2D vector
for (auto &row : vec) {
std::sort(row.begin(), row.end());
}
// Sorting the entire 2D vector based on the first element of each row
std::sort(vec.begin(), vec.end());
// Displaying the sorted 2D vector
for (const auto &row : vec) {
for (int num : row) {
std::cout << num << " ";
}
std::cout << std::endl;
}
return 0;
}