rotate left, rotate right
This function rotates a m x n matrix left or rightward.
The matrix must be rectangular. Consider filling short rows with blanks or zeros before rotating.
Indirect parameter passing is disabled
1
No. | Type | Description |
---|---|---|
1 input |
matrix | input matrix Matrix to be transposed |
Type | Description |
---|---|
matrix | Rotated matrix |
a[] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }, { 10, 11, 12 } };
echo matrix( "0", 3, '|', 'a[] = ', a[] );
echo("Rotate original matrix counterclockwise:");
l[] = rotate left( a[] );
echo matrix( "0", 3, '|', 'l[] = ', l[] );
echo("Rotate original matrix clockwise:");
r[] = rotate right( a[] );
echo matrix( "0", 3, '|', 'r[] = ', r[] );
echo("Rotate clockwise again:");
s[] = rotate right( r[] );
echo matrix( "0", 3, '|', 's[] = ', s[] );
| 1 2 3|
| 4 5 6|
a[] = | 7 8 9|
| 10 11 12|
Rotate original matrix counterclockwise:
| 3 6 9 12|
l[] = | 2 5 8 11|
| 1 4 7 10|
Rotate original matrix clockwise:
| 10 7 4 1|
r[] = | 11 8 5 2|
| 12 9 6 3|
Rotate clockwise again:
| 12 11 10|
| 9 8 7|
s[] = | 6 5 4|
| 3 2 1|