剑指offer 面试题20 顺时针打印二维数组
来源:互联网 发布:淘宝围巾店 编辑:程序博客网 时间:2024/06/06 01:09
<pre name="code" class="cpp">#include <iostream>using namespace std;void PrintCircle(int **matrix,int begin,int row,int col){for(int j=begin;j<col-begin;++j)cout<<matrix[begin][j]<<' ';//需要从上向下打印的前提 if(begin<row-1-begin){for(int i=begin+1;i<row-begin;++i)cout<<matrix[i][col-1-begin]<<' ';}//需要从右向左打印的前提if(begin<row-1-begin&&begin<col-1-begin){for(int j=col-2-begin;j>=begin;--j)cout<<matrix[row-1-begin][j]<<' ';}//需要从下向上打印的前提if(begin<row-2-begin&&begin<col-1-begin){for(int i=row-2-begin;i>begin;--i)cout<<matrix[i][begin]<<' ';}}void PrintMatrix(int **matrix,int row,int col){if(matrix==NULL||row<=0||col<=0)return;int begin=0;while(begin*2<row&&begin*2<col){PrintCircle(matrix,begin,row,col);++begin;}}/*void Print1D(int *matrix){cout<<matrix[8];} */int main(){//int m[][]={{1,2,3,4},{5,6,7,8},{9,10,11,12}};//PrintMatrix(m,3,4);//Print1D((int*)m);int **matrix=new int* [3];for(int i=0;i<3;++i){matrix[i]=new int [4];}for(int i=0;i<3;i++){for(int j=0;j<4;++j){matrix[i][j]=(i+1)*(j+1);}}//cout<<**matrix<<' '<<*(matrix[0])<<' '<<matrix[0][0]<<' ';PrintMatrix(matrix,3,4);for(int i=0;i<3;++i){delete[] matrix[i];matrix[i]=NULL;}delete[] matrix;matrix=NULL;}
0 0
- 剑指offer 面试题20 顺时针打印二维数组
- 剑指offer之顺时针打印二维数组
- 《剑指offer》面试题:顺时针打印矩阵
- 剑指offer面试题 顺时针打印矩阵
- 剑指offer面试题20顺时针打印矩阵
- [剑指offer][面试题20]顺时针打印矩阵
- 剑指offer 面试题20:顺时针打印矩阵
- 《剑指offer》面试题20顺时针打印矩阵
- 【剑指offer】面试题20:顺时针打印矩阵
- 剑指offer 面试题20 顺时针打印矩阵
- 剑指Offer:面试题20 顺时针打印矩阵
- 《剑指Offer》面试题20:顺时针打印矩阵
- 剑指offer 面试题20—顺时针打印矩阵
- 《剑指Offer》学习笔记--面试题20:顺时针打印矩阵
- 剑指offer--面试题20:顺时针打印矩阵--Java实现
- 【剑指Offer学习】【面试题20 : 顺时针打印矩阵】
- 剑指offer面试题20-顺时针打印矩阵
- 剑指offer-面试题20:顺时针打印矩阵
- Windows7事件ID10,WMI错误的解决方法
- Android 列表里的radioButton
- 命令模式、适配器模式与外观模式
- Android--多线程之Handler
- Android NDK官方下载链接(2014-12)
- 剑指offer 面试题20 顺时针打印二维数组
- ios+cocos2d-x 插页google广告
- java操作cassandra(安装)
- 百度地图使用实例
- ios开发 旋转屏幕supportedInterfaceOrientationsForWindow函数概要
- mysql 复习
- spring注解空指针异常 'sessionFactory' or 'hibernateTemplate' is required的解决方法
- Linux服务器性能评估(4)
- Ubuntu 12.04 安装有道词典