Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions counting_sort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/***********Program of Counting Sort***********/
/***********Author : Bhavya Jindal ************/
/**********************/
#include<stdio.h>
void CountingSort(int A[],int n,int k)
{
int c[k+1];
int i,j;
int b[n];
for(i=0;i<=k;i++)
{
c[i]=0;
}
for(i=0;i<=n-1;i++)
{
c[A[i]]=c[A[i]]+1;
}
for(i=1;i<=k;i++)
{
c[i]=c[i]+c[i-1];
}
for(j=n-1;j>=0;j--)
{
b[c[A[j]]-1]=A[j];
c[A[j]]=c[A[j]]-1;
}
for(i=0;i<n;i++)
{
printf("\t%d",b[i]);
}
}
void main()
{
int i,n,a[100];
printf("Enter the size of array : ");
scanf("%d",&n);
printf("Enter the elements of array : ");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int k=a[0];
CountingSort(a,n,k);
}