bucket sort algorithm c 2b 2b simple vector

Solutions on MaxInterview for bucket sort algorithm c 2b 2b simple vector by the best coders in the world

showing results for - "bucket sort algorithm c 2b 2b simple vector"
Tomas
31 Sep 2016
1void bucketsort (int a[ ], int n, int max)
2{
3	int i,j=0;
4	//initialize each bucket 0 and then make bucket empty.
5	int* buckets = calloc(max+1, size of (int));
6	for(int i=0; i<n; i++)
7		buckets[a[i]]++;
8	//now sort each bucket individually.
9	//sequentially empty each bucket in some array.
10	for(i=0; i<max; i++)
11		while (buckets[i]--)
12			b[j++]=i;
13	//display the array b as sorted list of elements.
14}