-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix_transform.h
More file actions
43 lines (34 loc) · 889 Bytes
/
Copy pathmatrix_transform.h
File metadata and controls
43 lines (34 loc) · 889 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
#ifndef __MATRIX_TRANSFORM__
#define __MATRIX_TRANSFORM__
void rotate_anti_clock_90_degree(int** a, int n) {
// we need a temp matrix to store internal result
int** t;
t = new int*[n];
for (int i = 0; i < n; ++i)
t[i] = new int[n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
t[i][j] = a[j][n - 1 - i];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
a[i][j] = t[i][j];
for (int i = 0; i < n; ++i)
delete[] t[i];
delete[] t;
}
void rotate_clock_wize_90_degree(int** a, int n) {
int** t;
t = new int*[n];
for (int i = 0; i < n; ++i)
t[i] = new int[n];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
t[i][j] = a[n - 1 - j][i];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
a[i][j] = t[i][j];
for (int i = 0; i < n; ++i)
delete[] t[i];
delete[] t;
}
#endif