MCPcopy Create free account
hub / github.com/Vishruth-S/CompetitiveCode / rotate

Function rotate

GeeksForGeeks/Rotate_by_90_degrees/Solution.cpp:21–40  ·  view source on GitHub ↗

Function to rotate the matrix by 90 degrees

Source from the content-addressed store, hash-verified

19
20//Function to rotate the matrix by 90 degrees
21void rotate(vector<vector<int> >& matrix)
22{
23 int r=matrix.size(); //Stores no. of rows in the matrix
24 int c=matrix[0].size(); //Stores no. of columns in the matrix
25 for(int i=0;i<r;i++){
26 for(int j=i+1;j<c;j++){
27 //Swapping the element at position (i,j) with position (j,i)
28 int temp=matrix[i][j];
29 matrix[i][j]=matrix[j][i];
30 matrix[j][i]=temp;
31 }
32 }
33 for(int i=0;i<r/2;i++)//Loop which travels through only one half of the number of rows
34 {
35 for(int j=0;j<c;j++){
36 //Swapping the elements in the first half of the rows with the second half of the rows
37 swap(matrix[i][j],matrix[r-1-i][j]);
38 }
39 }
40}
41
42int main()
43{

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected