Is it possible to sort matrix's row using STL sort
in c++?
like we sort 1-dimensional array from index x
to y
like:
int a[100];
sort(a+x, a+y+1);
how can I call sort
for int a[100][100]
if I want so sort i-th
row from x
to y
?
Is it possible to sort matrix's row using STL sort
in c++?
like we sort 1-dimensional array from index x
to y
like:
int a[100];
sort(a+x, a+y+1);
how can I call sort
for int a[100][100]
if I want so sort i-th
row from x
to y
?
You can do:
std::sort(a[i] + x, a[i] + y + 1);
The + 1
is necessary because the end iterator must point 1 element after the last element of the row vector.
If you want to sort the whole row, you can do it more elegantly like
std::sort(std::begin(a[i]), std::end(a[i]));