Anonymous user
Best shuffle: Difference between revisions
Removed stack overflow from C version
(Improved D version) |
(Removed stack overflow from C version) |
||
Line 152:
// all character positions, grouped by character
int *ndx1
if (ndx1 == NULL)
exit(EXIT_FAILURE);
for (int ch = 0, i = 0; ch < UCHAR_MAX; ch++)
if (counts[ch])
Line 162 ⟶ 164:
// regroup them for cycles
int *ndx2
if (ndx2 == NULL)
exit(EXIT_FAILURE);
for (int i = 0, n = 0, m = 0; i < len; i++) {
ndx2[i] = ndx1[n];
Line 186 ⟶ 190:
for (int i = 0; i < len; i++)
result[ndx2[i]] = txt[ndx1[i]];
free(ndx1);
free(ndx2);
}
|