Bucket Sort is a sorting method this subdivides the given data into various buckets depending on certain characteristic or Der, thus
Partially sorting them in the first go.
Then depending on the number of entities in each bucket, it employs either buckets sort again or some other ad hoc sort.
BUCKET SORT (A)
1. n←length [A]
2. For i = 1 to n do
3. Insert A[i] into list b[a[i]/b] where B is the bucket size
4. For i = 0 to n-1 do
5. Sort list B with insertion Sort
6. Concatenate the lists b[0], b[1],. . B[n-1] together in order.
Assumptions:
1#include <iostream>2#include <ctime>3#include <stdio.h>4#include <cstring>5#include <cstdlib>6#include <map>7#include <string>8 using namespacestd;9 voidBucket_sort (intArray[],intN)Ten { One intI, J; A intCount[n]; - for(i=0; I < n; i++) - { theCount[i] =0; - } - for(i=0; I < n; i++) - { +(Count[array[i]) + +; - } + for(i=0, j=0; I < n; i++) A { at for(; count[i]>0;(Count[i])--) - { -Array[j++] =i; - } - } - } in - #ifTEST to intMain () { + intArr[] = { the, $, the, -,802, -,2, the}; - intn =sizeof(arr)/sizeof(arr[0]); the //Radixsort (arr, n); * Bucket_sort (arr, n); $ print (arr, n);Panax Notoginseng } - #endif
View Code
Bucket sort (bucket sort)