#include <stdio.h>
#include <stdlib.h>
void counting_sort(int A[], int length)
{
int i; int frequency[10]; int *SortedArray;
for(i=0;i<10;i++)
{frequency[i]=0;}
SortedArray
=(int *)calloc(length
,sizeof(int)); for(i=0;i<length;i++)
{SortedArray[i]=-3;}
for(i=0;i<length;i++)
{frequency[A[i]]+=1;}
for(i=1;i<10;i++)
{frequency[i]+=frequency[i-1];}
// for(i=0;i<10;i++)
// {printf("%d\n",frequency[i]);}
int count=0;
while(count<length)
{
for(i=0;i<10;i++)
{
if(frequency[i]!=0 && SortedArray[frequency[i]-1]==-3)
{
SortedArray[frequency[i]-1]=i;
frequency[i]-=1;
count+=1;
}
}
}
for(i=0;i<length;i++)
{
A[i]=SortedArray[i];
}
}
int main(void) {
// data is in between 0 to 9
int array[200];
int response[200];
int length; int i;
for(i=0;i<length;i++)
counting_sort(array,length);
// *response=counting_sort(array,length);
for(i=0;i<length;i++)
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4Kdm9pZCBjb3VudGluZ19zb3J0KGludCBBW10sIGludCBsZW5ndGgpCnsgIAoJaW50IGk7IGludCBmcmVxdWVuY3lbMTBdOyBpbnQgKlNvcnRlZEFycmF5OwoJZm9yKGk9MDtpPDEwO2krKykKCXtmcmVxdWVuY3lbaV09MDt9CglTb3J0ZWRBcnJheT0oaW50ICopY2FsbG9jKGxlbmd0aCxzaXplb2YoaW50KSk7Cglmb3IoaT0wO2k8bGVuZ3RoO2krKykKCXtTb3J0ZWRBcnJheVtpXT0tMzt9Cglmb3IoaT0wO2k8bGVuZ3RoO2krKykKCXtmcmVxdWVuY3lbQVtpXV0rPTE7fQoJCglmb3IoaT0xO2k8MTA7aSsrKQoJe2ZyZXF1ZW5jeVtpXSs9ZnJlcXVlbmN5W2ktMV07fQovLwlmb3IoaT0wO2k8MTA7aSsrKQovLwl7cHJpbnRmKCIlZFxuIixmcmVxdWVuY3lbaV0pO30KCglpbnQgY291bnQ9MDs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