螺旋打印二维数组
public static void Show(){ // 1,2,3,7,8,4,9,5,6 int[][] arr = new int[][]{ new int[]{1,2,3}, new int[]{5,6,7}, new int[]{9,4,8} }; int tr = 0; int tc = 0; int dr = arr.Length - 1; int dc = arr[1].Length - 1; while(tr <= dr && tc <= dc){ PrintLX(arr,tr,tc,dr,dc); tr++; tc++; dr--; dc--; } } public static void PrintLX(int[][] arr,int a,int b,int c,int d){ if(a==c){// 同一行 for(int i=d; i<=c;i++) System.Console.WriteLine(arr[a][i]); } else if(b==d){ // 同一列 for(int i=b; i<=d;i++) System.Console.WriteLine(arr[i][d]); }else{ int curC = a; int curR = b; while(curC < d){ // 先行 System.Console.WriteLine(arr[a][curC]); curC++; } while(curR < c){ // 列 System.Console.WriteLine(arr[curR][d]); curR++; } while(curC > 0){ // 先行 System.Console.WriteLine(arr[c][curC]); curC--; } while(curR > 0){ // 列 System.Console.WriteLine(arr[curR][b]); curR--; } } }