I'm studying the C language with a Harvey Deitel book.
Trying to solve an exercise that asked to write a good sorting algorithm, I did this:
void sort(int v[], int d){
int max = 0;
for(int i = 0; i < d; i++){
if(v[i] > max)max = v[i];
}
int v2[max+1];
int v3[max+1];
for(int i = 0; i < max+1; i++){
v2[i] = -1;
v3[i] = 0;
}
for(int i = 0; i < d; i++){
if(v3[v[i]] == 0){
v2[v[i]] = v[i];
v3[v[i]]++;
}
else {
v3[v[i]]++;
}
}
int j = 0;
for(int i = 0; i < max+1; i++){
if(v2[i] != -1){
for(int k = 0; k < v3[i]; k++){
v[j] = v2[i];
j++;
}
}
}
}
good sorting algorithm
good?) \$\endgroup\$