I am trying to implement a counting sort function for Pset3 find (more comfortable), and have written up the code below:
void csort(int values[], int n)
{
int limit = 5; // CHANGE LIMIT HERE
int counts[limit];
for(int i = 0; i < n; i++)
{
counts[values[i]-1]++;
}
int nindex = 0;
for(int k = 0; k < limit; k++)
{
for(int j = 0; j < counts[k]; j++)
{
values[nindex] = k;
nindex++;
}
}
}
This is returning a "Segmentation fault" error, which upon a quick Google search seemed to indicate memory issues (some kind of infinite loop?) Does anyone have any idea what might be causing this and what the best approach to remedying the problem might be? Thanks!