1
I am trying to sort a char vector using the selection method (Seletion Sort), but it is returning me the vector exactly the same way, without even making a change. Can someone point me to the error in the code?
void selectionSortChar(char v[][30], int max) {
int i, j, min;
char aux[30];
for (i = 0; i < (max - 1); i++) {
min = i;
for (j = i + 1; j < max; j++) {
if (stricmp(v[j], v[j + 1]) > 0) {
min = j;
}
}
if (i != min) {
strcpy(aux, v[j]);
strcpy(v[j], v[j + 1]);
strcpy(v[j + 1], aux);
}
}
mostraVetorChar(v, 6);
}
I didn’t test it, I don’t know where the mistake is, but looking real quick, the last
if
shouldn’t be min instead of j no?– Felipe Avelar