矩阵的翻转

// 翻转矩阵.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;
}
一圈一圈的转
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值