Jump to content

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[ = malloc((unsigned int)len] * sizeof(int));
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[ = malloc((unsigned int)len] * sizeof(int));
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);
}
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.