int i,r,d,c;
int * count = newIntArray(R + 1);
StringElementsArray aux; // aux Array
createStringElementsArray(&aux,N); // create aux array
for (d = W-1; d >= 0; d--) {
// reset count[] array
for (i = 0; i < R+1; i++)
count[i]=0;
// compute frequency counts
for (i = 0; i < N; i++)
count[a->str[i][d] + 1]++;
// transform counts to indicies
for (r = 0; r < R; r++)
count[r+1] += count[r];
// distribute
for (i = 0; i < N; i++) {
c = a->str[i][d];
aux.str[count[c]] = a->str[i];
aux.len[count[c]] = a->len[i];
count[c]++;
}
// copy back
for (i = 0; i < N; i++) {
a->str[i] = aux.str[i];
a->len[i] = aux.len[i];
}
// Trace of iterations for LSD string sort
printf("\nLSD Sorted List (right to left) after sorting key %d:\n",d);
for (i = 0; i < N; i++)
printf("\t%s\n",a->str[i]);
}
Sem comentários:
Enviar um comentário