-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotate Matrix.txt
More file actions
49 lines (38 loc) · 924 Bytes
/
Copy pathRotate Matrix.txt
File metadata and controls
49 lines (38 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
You are given an n x n 2D matrix representing an image.
Rotate the image by 90 degrees (clockwise).
You need to do this in place.
Note that if you end up using an additional array, you will only receive partial score.
Example:
If the array is
[
[1, 2],
[3, 4]
]
Then the rotated array becomes:
[
[3, 1],
[4, 2]
]
*/
/**
* @input A : 2D integer array
* @input n11 : Integer array's ( A ) rows
* @input n12 : Integer array's ( A ) columns
*
* @Output Void. Just modifies the args passed by reference
*/
void rotate(int** A, int n11, int n12) {
int i,j;
for(i=0;i<n11/2;i++)
{
for(j=i;j<n12-1-i;j++)
{
int temp=A[i][j];
A[i][j]=A[n12-1-j][i];
A[n12-1-j][i]=A[n12-1-i][n12-1-j];
A[n12-1-i][n12-1-j]=A[j][n12-1-i];
A[j][n12-1-i]=temp;
}
}
}