Narendra
0
Q:

#include <bits/stdc++.h>

// C++ program to sort the vector 
// of array by sort() function 
// using STL in c++ 
  
#include <algorithm> 
#include <array> 
#include <iostream> 
#include <vector> 
using namespace std; 
  
#define N 3 
  
// Function to print vector of arrays 
void print(vector<array<int, N> > vect) 
{ 
  
    // Displaying the vector of arrays 
    // ranged for loop is supported 
    for (array<int, N> i : vect) { 
        for (auto x : i) 
            cout << x << " "; 
        cout << endl; 
    } 
} 
  
// Driver code 
int main() 
{ 
    // std::array is a container that 
    // encapsulates fixed size arrays. 
    vector<array<int, N> > vect; 
    vect.push_back({ 1, 2, 3 }); 
    vect.push_back({ 10, 20, 30 }); 
    vect.push_back({ 30, 60, 90 }); 
    vect.push_back({ 10, 20, 10 }); 
  
    cout << "Vector of arrays"
         << " before sorting: \n"; 
    print(vect); 
  
    // Sorting the vector using built-in sort() 
    // defined in algorithm header in C++ STL 
    sort(vect.begin(), vect.end()); 
  
    cout << "Vector of arrays"
         << " after sorting: \n"; 
    print(vect); 
  
    // End of program 
    return 0; 
} 
0

New to Communities?

Join the community