Java经典算法题-转圈打印矩阵

本文介绍如何用Java解决经典算法问题——转圈打印矩阵。通过实例展示矩阵的转圈输出顺序,涉及二维数组的操作和逻辑控制。
摘要由CSDN通过智能技术生成

【题目】 给定一个整型矩阵matrix,请按照转圈的方式打印它。 
     *例如: 1   2   3   4 5   6   7   8 9  10  11  12 13 14  15  16 
      打印结果为:1,2,3,4,8,12,16,15,14,13,9, 5,6,7,11, 10 

public class PrintMatrixSpiralOrder {
	/*
	 * 转圈打印矩阵
	 * row行
	 * column列
	 * 行长度:array.length 
	 * 列长度:array[i].length 
	 */
	public static void spiralOrderPrint(int[][] Matrix) {
		int rowLeft=0;//左上角行号
		int columnLeft=0;//左上角列号
		int rowRight=Matrix.length-1;//(右下角行号)
		int columnRight=Matrix[0].length-1;//(右下角列号)
		while (rowLeft<=rowLeft&&columnLeft<columnRight) {
			printEdge(Matrix,rowLeft++,columnLeft++,rowRight--,columnRight--);
		}
		
	}

	private static void printEdge(int[][] Matrix, int rowLeft, int columnLeft, 
			                                      int rowRight, int 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值