示例#1
0
 private static void Transpose <T>(ISquareMatrix <T> matrix)
 {
     for (int row = 0; row < matrix.GetSize() - 1; row++)
     {
         for (int col = row + 1; col < matrix.GetSize(); col++)
         {
             Swap(ref matrix.At(row, col), ref matrix.At(col, row));
         }
     }
 }
示例#2
0
    public static void Rotate90DegreesClockwise <T>(ISquareMatrix <T> matrix)
    {
        Transpose(matrix);

        // Mirror left to right
        for (int row = 0; row < matrix.GetSize(); row++)
        {
            for (int col = 0; col < matrix.GetSize() / 2; col++)
            {
                Swap(ref matrix.At(row, col), ref matrix.At(row, matrix.GetSize() - 1 - col));
            }
        }
    }
示例#3
0
    public static void Rotate90DegreesCounterclockwise <T>(ISquareMatrix <T> matrix)
    {
        Transpose(matrix);

        // Mirror top to bottom
        for (int col = 0; col < matrix.GetSize(); col++)
        {
            for (int row = 0; row < matrix.GetSize() / 2; row++)
            {
                Swap(ref matrix.At(row, col), ref matrix.At(matrix.GetSize() - 1 - row, col));
            }
        }
    }