#include <stdio.h>
void CountSort(int *arr,int len,int *temp){
int i,j;
int count[len];
for(i = 0;i < len;i++)
count[i] = 0;
for(i = 0;i < len-1;i++){
for(j = i+1;j < len;j++){
if(arr[i] > arr[j]){
count[i]++;
}else
count[j]++;
}
}
for(i = 0;i < len;i++){
temp[count[i]] = arr[i];
}
}
int Max_Num(int *arr,int len){
int max = 0;
for(int i = 0;i<len ;i++){
if(arr[i]>max){
max = arr[i];
}
}
return max;
}
void Count_Sort(int *arr,int len,int *temp,int max){
int i,j,count[max];
for(i = 0 ; i<max;i++)
count[i]=0;
for(i = 0;i < len ;i++){
count[arr[i]]++;
}
for(i = 1;i<len;i++){
count[i]+=count[i-1];
}
for(j = len-1;j>=0;j--){
count[arr[j]]--;
temp[count[arr[j]]] = arr[j];
}
}
void display(int *arr,int len){
for(int i=0;i<len;i++)
printf("%d ",arr[i]);
}
int main(){
int arr[] = {9,5,7,10,8};
int len = sizeof(arr) / sizeof(int);
int temp[len];
CountSort(arr,len,temp);
display(temp,len);
printf("\n");
int arr2[]={2,5,3,0,2,3,0,3};
int len2 = sizeof(arr2) / sizeof(int);
int temp2[len2];
int max = Max_Num(arr2,len2);
Count_Sort(arr2,len2,temp2,max);
display(temp2,len2);
}