

Initializing a 2D Vector with random values:.#include //For 2D vector and sort() function

Including header files necessary for the vector and sort operations, bits/stdc++.h is the header file comprised of several header files and is useful for many operations/functions.

In C++, we can sort particular rows in the 2D vector using sort() function, by default the sort() functions sorts the vector in ascending order. Sorting particular row (Ascending order): push_back() operation appends the value passed in the function to the end of the vector. We can fill up values in the vectors during initialization or using push_back() operation. Here 'v' is the name of vector of vectors(2D vector) and 'int' is the data type vector > v Here 'v' is the name of 1D vector and 'int' is the data type stored. In this article, we will explore different ways to sort a 2 dimensional (2D) vector in C++ which includes sorting by row, column, a specific row or a specific column. It is an matrix implemented with the help of vectors. Vector elements are places in contiguous storage so that they can be accessed and traversed using iterators. Vectors are data structures similar to array but with features such as dynamic memory, resizable container, insertion and deletion of elements.
