0
Is it possible to create a transpose of a matrix by using only one 2D array(input array)?
I was thinking of making either changes in the input matrix or using another temporary matrix to copy data and to delete the input matrix (if this is possible). I am not really sure what we should do I'm just curious.
6 Respostas
+ 1
http://www.sololearn.com/app/cplusplus/playground/cZ3g6qhH7Yf8/
#include <iostream>
using namespace std;
template <int _size>
void print2dim(int matrix[][_size]) {
for (int i=0; i<_size; ++i) {
for (int j=0; j<_size; ++j)
cout << matrix[i][j];
cout << endl;
}
}
template <int _size>
void transpose(int matrix[][_size]) {
for (int i=1; i<_size; ++i)
for (int j=0; j<i; ++j) {
int tmp=matrix[i][j];
matrix[i][j]=matrix[j][i];
matrix[j][i]=tmp;
}
}
int main() {
int matrix[3][3] =
{
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
print2dim(matrix);
cout << endl;
transpose(matrix);
print2dim(matrix);
return 0;
}
0
of course you can if the matrix is a square matrix.
0
but I want use just one matrix
0
you can.
0
can you write a code
I mean the sample
0
thanks you very much