题目:旋转图像
C语言解题
void rotate(int** matrix, int matrixRowSize, int *matrixColSizes) {
int temp;
for (int i = 0; i < matrixRowSize; i++)
{
for (int j = i; j < *matrixColSizes; j++)
{
temp = matrix[i][j];
matrix[i][j] = matrix[j][i];
matrix[j][i] = temp;
}
}
for (int i = 0; i < *matrixColSizes; i++)
{
for (int j = 0; j < matrixRowSize/2; j++)
{
temp = matrix[i][j];
matrix[i][j] = matrix[i][matrixRowSize - j - 1];
matrix[i][matrixRowSize - j - 1] = temp;
}
}
}
将矩阵转置,再将每一行逆序。