[Solved] Browse a matrix


Here the solution I found :

    private static IEnumerable<int> ComputeMatrix(int[,] matrix)
    {
        // check args
        if (matrix.Rank != 2) { throw new ArgumentException("matrix should have a rank of 2"); }
        if (matrix.GetUpperBound(0) != matrix.GetUpperBound(1)) { throw new ArgumentException("matrix should have the same size");}

        // indice treated
        List<int> treatedIndex = new List<int>();

        for (int i = 0; i <= matrix.GetUpperBound(0); i++)
        {
            if (treatedIndex.Count == matrix.GetUpperBound(0)) 
                break;

            // distance minimum between 2 points
            int distanceMin = Int32.MaxValue;

            // next iteration of index
            int nextI = i;

            // add the index to ignore in the next iteration
            int nextJ = -1;

            for (int j = 0; j <= matrix.GetUpperBound(1); j++)
            {
                if (treatedIndex.IndexOf(j) == -1)
                {
                    if (matrix[i, j] != 0 && matrix[i, j] < distanceMin)
                    {
                        distanceMin = matrix[i, j];
                        nextI = j;
                        nextJ = i;
                    }
                }
            }

            i = nextI - 1;
            treatedIndex.Add(nextJ);
            yield return distanceMin;
        }
    }

solved Browse a matrix