Home / C / C program for counting sort

C program for counting sort

This c program will demonstrate how will counting sort work. 

void main()

{

int a[20],b[11],c[20],i,n;

clrscr();

printf(“Enter total number of elements : “);

scanf(“%d”,&n);

printf(“Enter Elements in the range of 1-10\n”);

for(i=0;i

{

scanf(“%d”,&a[i]);

}

for(i=0;i<11 ;i++)

{

 b[i]=0;

}

 //Module for Sorting using Counting Sort Start

for(i=0;i

{

b[a[i]]+=1;

}

for(i=1;i<11;i++)

{

b[i]=b[i]+b[i-1];

}

for(i=n-1;i>=0;i–)

{

c[b[a[i]]]=a[i];

b[a[i]]-=1;

}

printf(“Elements after sorting is \n”);

{

 printf(“%d\t”,c[i]);

}

getch();

}

OUTPUT

Tags: c program for sorting technique, Counting Sort in C

Check Also

Restrict Mouse Pointer Position C Graphics Program

This C Program will restrict the Mouse Pointer location or to a particular position or x,y ...

Leave a Reply

Your email address will not be published. Required fields are marked *

Preventing spam * Time limit is exhausted. Please reload the CAPTCHA.