Classical sorting algorithm-pig nest sorting pigeonhole sort

Source: Internet
Author: User

Classical sorting algorithm-pig nest sorting pigeonhole sort

The principle is similar to bucket sorting. It also requires a very large Pigeon nest. [This is called Bucket in bucket sorting. the name doesn't matter.]

Pigeon nest is actually an array. The index position of the array indicates the value, and the value of the index position indicates the number of occurrences. If all the indexes are 1 or 0, the bucket is sorted.

For example

VaR pigeonhole = new int [100];

The value of pigeonhole [0] indicates the number of occurrences of 0...

The value of pigeonhole [1] indicates the number of occurrences of 1...

The value of pigeonhole [2] indicates the number of occurrences of 2...

ReferenceHttp://hi.baidu.com/wangxvfeng101/blog/item/a2c22560e57260c58cb10d8c.html

The code is for reference only.

/// Nest sorting /// </Summary> /// <Param name = "unsorted"> array to be sorted </param> /// <Param name = "maxnumber"> maximum number of columns in the array to be sorted, </param> /// <returns> </returns> static int [] pogeon_sort (INT [] unsorted, int maxnumber = 10) {int [] pogeonhole = new int [maxnumber + 1]; foreach (VAR item in unsorted) {pogeonhole [item] ++;} return pogeonhole; /** pogeonhole [10] = 4; the meaning is * Four 10 appear in the array to be sorted, the same as the other */} static void main (string [] ARGs) {int [] x = {99, 65, 24, 47, 47, 50, 99, 88, 66, 33, 66, 67, 31, 18, 24 }; vaR sorted = pogeon_sort (x, 99); For (INT I = 0; I <sorted. length; I ++) {for (Int J = 0; j <sorted [I]; j ++) {console. writeline (I) ;}} console. readline ();}

Back to main directory [classic Sorting Algorithm] [Collection]

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.