I am trying to sort the elements in 2d array like this:
338 640 723.771 62.1603
364 804 882.56 65.642
199 664 693.179 73.3166
I need to sort them regards to 3rd and 4th columns.
For instance for the 3rd column:
199 664 693.179 73.3166
338 640 723.771 62.1603
364 804 882.56 65.642
For the 4th column:
338 640 723.771 62.1603
364 804 882.56 65.642
199 664 693.179 73.3166
I hope I could explain what I want to do. Thanks for help already..
Answer:
I've found what need it. I am putting the codes here maybe it could be helpful for someone else.
this is compare function for columns:
bool Compare(vector<double> A, vector<double> B) {
return (A[2] < B[2]); // 2 means which column that you want to compare
}
and this is the sorting code:
std::sort(dots.begin(), dots.end(), &Compare); // "dots" needs to be a vector. in this case its a 2d double vector
the source is : https://stackoverflow.com/a/37516971/5331586