answersLogoWhite

0

C program for counting sort

Updated: 12/13/2022
User Avatar

Wiki User

12y ago

Best Answer

#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int i,j,m,a[20],b[20],c[20],max;

printf("enter no of elements");

scanf("%d",&m);

printf("enter elements");

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

{

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

}

max=a[i];

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

{

if(max<a[i])

{

max=a[i];

}

}

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

{

c[i]=0;

}

for(j=0;j<=m;j++)

{

c[a[j]]=c[a[j]]+1;

}

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

{

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

}

for(j=m;j>=1;j--)

{

b[c[a[j]]]=a[j];

c[a[j]]=c[a[j]]-1;

}

printf("AFTER SORTING");

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

{

printf("%d",b[i]);

}

getch();

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C program for counting sort
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program that read phrase and print the number of lower-case letter in it using function of counting?

write a program that reads a phrase and prints the number of lowercase latters in it using a function for counting? in C program


What is the C program for heap sort using recursion?

123


A C program using dynamic memory allocation to sort n names in ascending order?

Writing a C program that uses dynamic memory allocation to sort names in ascending order is a typical computer science assignment. To write this program, you must be in UNIX.


Write a program in c to sort the details of 10 students using the structure?

for(i = 0; i &lt; num_students; i ++){ sort(student[i]); } That's what you get when you're that specific!


How do you write a c plus plus program to sort a vector of strings using MSD radix sort?

The standard library sort algorithm automatically uses MSD radix to sort strings: std::vector&lt;std::string&gt; vs = {"a", "b", "c" "d", "ab"}; std::sort(vs.begin(), vs.end()); After sorting, the order will be: {"a", "ab", "b", "c", "d"}


Write c program to find median?

If you are using an array : sort using qsort() then take middle element.


What is the sort cut for running c plus plus program?

It depends on the particular IDE. Visual Studio uses &lt;Ctrl&gt;F5 to start a program in non-debug mode, and F5 to start a program in debug mode.


Sorting an array in PHP without using sort function?

plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++


Write a c program to sort an unsorted stack?

A stack is implicitly sorted by hierarchical nested order. It does not make sense to sort a stack. Do you mean a list? If so, please ask the question again.


C program was introduced in the year?

c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.


Features of c program?

the features of a C program


C program to fine the largest of 10 given number?

first sort the ten numbers in descending order and print the first number. That will be the largest no