Q:

bucket sort algorithm c++ simple -vector

void bucketsort (int a[ ], int n, int max)
{
	int i,j=0;
	//initialize each bucket 0 and then make bucket empty.
	int* buckets = calloc(max+1, size of (int));
	for(int i=0; i<n; i++)
		buckets[a[i]]++;
	//now sort each bucket individually.
	//sequentially empty each bucket in some array.
	for(i=0; i<max; i++)
		while (buckets[i]--)
			b[j++]=i;
	//display the array b as sorted list of elements.
}
1

New to Communities?

Join the community