Bucket sort (bucket sort)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.