Tuesday , December 6 2016
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”);

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

{

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

}

getch();

}

OUTPUT

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

Check Also

Hide Mouse Pointer C Program

How to Hide a Mouse Pointer Program in C : This program will show and hide ...

Leave a Reply

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

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