Skip to content

Instantly share code, notes, and snippets.

@AliAkberAakash
Last active January 6, 2020 18:41
Show Gist options
  • Save AliAkberAakash/3eff1f6dd81c6d272b128a88559080e5 to your computer and use it in GitHub Desktop.
Save AliAkberAakash/3eff1f6dd81c6d272b128a88559080e5 to your computer and use it in GitHub Desktop.
//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