// 翻转矩阵.cpp : 定义控制台应用程序的入口点。
//
#include"stdafx.h"
#include<iostream>
#include<time.h>
#include<algorithm>
usingnamespace std;
#define M8
int randgener()
{
return(rand()%100);
}
void print(int** a)
{
for(int i=0; i< M; i++)
{
for(int j=0; j< M; j++)
{
cout<< a[i][j]<<"\t";
}
cout<< endl;
}
}
void swap(int& a ,int& b)
{
int temp= a;
a= b;
b= temp;
}
voidReserve(int** a,int m)
{
if(NULL== a)
return;
int low=0;
int high= m;
while(low< high)
{
swap(a[low][low], a[low][high]);
swap(a[low][low], a[high][high]);
swap(a[low][low], a[high][low]);
for(int i= low+1; i<= high-1; i++)
{
swap(a[low][i], a[i][high]);
swap(a[low][i], a[high][m-i]);
swap(a[low][i], a[m-i][low]);
}
low++;
high--;
cout<< endl;
}
}
int main()
{
int** a=newint*[M];
int* b=newint[M*M+1];
for(int i=0; i< M; i++)
a[i]= b+ i*M;
generate(b, b+M*M, randgener);//初始化矩阵---好方法
print(a);
Reserve(a, M-1);
cout<< endl;
print(a);
return0;
}
一圈一圈的转