需求
按照顺时针螺旋顺序,返回矩阵中的所有元素
实现代码
package RQcode;
import java.util.ArrayList;
import java.util.List;
public class Matrix {
private final static String GAP_DEFAULT = " ";
private static int matrixLength = 0;
public static void main(String[] args) {
List<Integer[]> matrix = buildMatrix(7, 8);
logMatrix(matrix);
clockwiseOutput(matrix);
}
public static void clockwiseOutput(List<Integer[]> matrix) {
if (matrix == null || matrix.size() <= 0) {
System.out.println("matrix is invalid, cannot output by clockwise!");
return;
}
System.out.println("clockwise matrix:");
int rowMaxIndex = matrix.size() - 1;
int columnMaxIndex = matrix.get(0).length - 1;
int rowMinIndex = 0;
int columnMinIndex