Hello, I have a char array initialized as follows:
#include <iostream>
using namespace std;
main(){
char matriz[6][5]={
{'F','H','V','D','U'},
{'E','L','Q','U','E'},
{'P','E','R','S','E'},
{'V','E','R','A','A'},
{'L','C','A','N','Z'},
{'A','Z','Z','Z','Z'}};
}
And I need to transpose the columns, alphabetically ordering the first row, that is, the row that contains {'F', 'H', 'V', 'D', 'U'}.
The matrix that I need to obtain is the following:
char matriz[6][5]={
{'D','F','H','U','V'},
{'U','E','L','E','Q'},
{'S','P','E','E','R'},
{'A','V','E','A','R'},
{'N','L','C','Z','A'},
{'Z','A','Z','Z','Z'}};
I have managed to alphabetize the first row only, but I can not manage to move the rest of the column to perform the ordering as a single block.
Update:
Ok I finally manage to transpose it but now at least if the first row of the matrix has the same letters, they are sorted alphabetically but the values of only one of the two columns are transposed. Here is the code I have to transpose them.
for(int j=0;j<largo;j++){
for(int i=0;i<largo;i++){
if(textoB[0][j]==texto[0][i]&&textoB[0][j+1]==texto[0][i]){
texto[0][i]='*';
for(int k=1;k<fila;k++){
textoB[k][j]=texto[k][i];
}
}
else if(textoB[0][j]==texto[0][i])
for(int k=1;k<fila;k++){
textoB[k][j]=texto[k][i];
}
}
}
Text being the original unordered matrix and textB the original matrix with first row alphabetically arranged (unordered in the other spaces).