转置让我写成了对角线交换。。。
还是要记录下
对角线交换代码:
public int[][] Transpose(int[][] matrix) { int temp=0; int m = matrix.Length, n = matrix[0].Length; for(int i=0;i<m;i++) { for(int j=i+1;j<n;j++) { temp=matrix[i][j]; matrix[i][j]=matrix[j][i]; matrix[j][i]=temp; } } return matrix; }
转置代码:
public int[][] Transpose(int[][] matrix) { int m = matrix.Length, n = matrix[0].Length; int[][] transposed = new int[n][];//二维矩阵初始化 for (int i = 0; i < n; i++) { transposed[i] = new int[m]; } for (int i = 0; i < m; i++) { for (int j = 0; j < n; j++) { transposed[j][i] = matrix[i][j]; } } return transposed; }
标签:transposed,matrix,c#,代码,矩阵,++,int,Length From: https://www.cnblogs.com/Dongmy/p/18170117