首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

矩阵旋转90渡的两种方法

2013-03-25 
矩阵旋转90度的两种方法java语言:第一种:public static void rotate(char a[][],int N){int layerfor(lay

矩阵旋转90度的两种方法

java语言:

第一种:

public static void rotate(char a[][],int N){    int layer;    for(layer=0; layer<N/2; layer++)    {        int first = layer;                      int last = N-1-layer;                       int i;        for(i=layer; i<last; i++)        {                int offset = i-layer;                char top = a[first][i];                a[first][i] = a[last-offset][first];                a[last-offset][first] = a[last][last-offset];                a[last][last-offset] = a[i][last];                a[i][last] = top;        }    }}

显然,第二种的时间复杂度要比第一种小很多。

热点排行