Last active
December 26, 2015 13:19
-
-
Save aaani/7157733 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<int N> | |
void rotate90Clockwise(int (&matrix)[N][N]){ | |
//Transpose the matrix | |
int temp; | |
for(int i=0;i<N;i++){ | |
for(int j=0;j<i;j++){ | |
temp=matrix[i][j]; | |
matrix[i][j]=matrix[j][i]; | |
matrix[j][i]=temp; | |
} | |
} | |
//For clockwise rotation reverse rows, for anti-clockwise reverse columns | |
for(int i=0;i<N;i++){ | |
for(int j=0;j<N/2;j++){ | |
temp = matrix[i][j]; | |
matrix[i][j] = matrix[i][N-j-1]; | |
matrix[i][N-j-1] = temp; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment