I need to sort 2d array rows in ascending order of their first elements, like in example
{{5,7,6},{2,9,6},{4,8,1}} --> {{2,9,6},{4,8,1},{5,7,6}}
I can find max element in row, but i don't now how to sort the rows.
public double[] maxInRow(double[,] n)
{
double[] result = new double[n.GetLength(0)];
for (int i = 0; i < n.GetLength(0); i++)
{
double max = 0;
for (int j = 0; j < n.GetLength(1); j++)
{
if (max < n[i,j])
{
max = n[i,j];
}
}
result[i] = max;
}
return result;
}
Can you advice something?
Thanks in advance!