矩阵翻转算法

题目:

Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes

write a method to rotate the image by 90 degrees. Can you do this in place?

解决思想:

顺时针:先将矩阵转置   再依次将各行首尾互换

逆时针:先将矩阵转置   再依次将各列首尾互换

以4X4矩阵逆时针旋转90°为例:

#include 
using namespace std;

void swap(int &a, int &b){
    int t = a;
    a = b;
    b = t;
}
void transpose(int a[][4], int n){
    for(int i=0; i




你可能感兴趣的:(算法至上)