Iterating through a 2D vector using one use case of for loop gives segmentation fault

Advertisements I needed to write a simple method that calculates the highest element in a matrix data (implemented in this case using a 2D vector). Inside the method, initially, I was accessing each element in the 2D vector using the one form (the most common one) of for loop which gave a "segmentation fault". Unfortunately,… Read More Iterating through a 2D vector using one use case of for loop gives segmentation fault

How to sort an vector based on any column value by passing the column index as input?

Advertisements I have already tried the below code but i want to use this same function for sorting based on different columns. This given code is sorting based on first column only. bool sortcol( const vector <int> v1, const vector <int> v2) { return v1[0]<v2[0]; } sort(ArrOfTimings.begin(), ArrOfTimings.end(), sortcol); Is there any way possible to… Read More How to sort an vector based on any column value by passing the column index as input?