Skip to content

Commit 5e0c7ef

Browse files
author
lightmen
committed
add rotate-image
1 parent d109f0b commit 5e0c7ef

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

rotate-image.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
static void swap(int *a, int *b)
2+
{
3+
*a ^= *b;
4+
*b ^= *a;
5+
*a ^= *b;
6+
}
7+
void rotate(int** matrix, int matrixRowSize, int matrixColSize) {
8+
int i,j;
9+
int start,end;
10+
for(j = 0; j < matrixColSize; ++j)
11+
{
12+
start = 0;
13+
end = matrixRowSize - 1;
14+
while(start < end){
15+
swap(&matrix[start][j],&matrix[end][j]);
16+
++start;
17+
--end;
18+
}
19+
}
20+
21+
for(i = 0; i < matrixRowSize; ++i)
22+
for(j = i + 1; j < matrixColSize; ++j){
23+
swap(&matrix[i][j],&matrix[j][i]);
24+
}
25+
}

0 commit comments

Comments
 (0)