Merge pull request #75 from ashish4321/master

adding counting sort
This commit is contained in:
Anup Kumar Panwar 2017-10-15 00:30:10 +05:30 committed by GitHub
commit 98005e3fde
2 changed files with 28 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

28
Untitled.c Normal file
View File

@ -0,0 +1,28 @@
#include <stdio.h>
int main()
{
int i,n,l=0;
scanf("%d",&n);
int a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]>l)
l=a[i];
}
int b[l+1]={0};
for(i=0;i<n;i++)
b[a[i]]++; //hashing number to array index
for(i=0;i<(l+1);i++)
{
if(b[i]>0)
{
while(b[i]!=0) //for case when number exists more than once
{
printf("%d ",i);
b[i]--;
}
}
}
return 0;
}