Last active
January 6, 2020 18:41
-
-
Save AliAkberAakash/3eff1f6dd81c6d272b128a88559080e5 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
//traverse through the layers | |
for(int layer=0; layer<n/2; layer++) | |
{ | |
int first = layer; | |
int last = n-layer-1; | |
//traverse through start to end | |
for(int i=first; i<last; i++) | |
{ | |
//creating the offset | |
int offset = i - first; | |
//storing the top value | |
int top = matrix[first][i]; | |
//store left in top | |
matrix[first][i] = matrix[last-offset][first]; | |
//store bottom in left | |
matrix[last-offset][first] = matrix[last][last-offset]; | |
//store right in bottom | |
matrix[last][last-offset] = matrix[i][last]; | |
//store top in right | |
matrix[i][last] = top; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment