I have a vector of vectors, as follows:
vector< vector<int> > intervals;
Basically, I need to sort the vector, using STL’s sort (), but I need to sort ‘intervals’, for intervals[i][0]. So, sort the vector objects by the [0] element of each object.
How can I do this? Thank you in advance.
std::sort takes a comparator function of object as third argument, so you can define a less-than operator that takes two vector and compares their first elements.