Bucket Sort in C and C++

Here you will get program for bucket sort in C and C++.

In bucket sort algorithm the array elements are distributed into a number of buckets. Then each bucket sorted individually either using any other sorting algorithm or by recursively applying bucket sort.

Take example shown in below image.

Bucket Sort

Elements are distributed among buckets

Bucket Sort

Then, elements are sorted within each bucket

Below is the program to implement this algorithm. In this program it is assumed that the array elements are between 0 to 10.

Program for Bucket Sort in C

Program for Bucket Sort in C++


Before sorting:
3 6 5 1 8 4 3 1

After sorting:
1 1 3 3 4 5 6 8

6 thoughts on “Bucket Sort in C and C++


    there is mistake in c++ program which is value is SIZE is not given

  2. birjesh

    ohh…hello it’s not bucket sort ,your coding is almost like counting sort……….u r making a fool of us …..first learn what bucket sort is okk

  3. M G Nkwenkwat

    This is not working at all. I changed the values in the array and no sorting takes place

  4. k2

    This is not Bucket Sort but Counting Sort – the difference is that in Counting Sort you count how much times the number appears in array (like in your code) which is good for integers but bad for floats. Bucket Sort works with floats – it creates “buckets” – array of lists, divide elements by liknking them to appropriate lists (that every element in list a[i-1] are lower than element in list a[i], every elements in list a[i] are lower than every element in list a[i+1] etc.) next you sort elements in lists using whatever you want (there are few elements than this can be Insertion Sort – will be fast) and then you rewrite sorted elements form lists back to array.


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.