Classic sort algorithm-pigeon nest sort pigeonhole

Source: Internet
Author: User

Classic Sort algorithm-pigeon nest sort pigeonhole

The principle is similar to the bucket sort, also need a very big pigeon nest [bucket sort tube This is called bucket, name doesn't matter]

The Pigeon nest is actually an array, the index position of the array represents the value, the value of the index position indicates the number of occurrences, if all are 1 or 0 times that is the bucket sort

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 ...

Reference http://hi.baidu.com/wangxvfeng101/blog/item/a2c22560e57260c58cb10d8c.html

The code is for reference only, welcome Anthony Mistake

        Pigeon Nest Sort///</summary>//<param name= "unsorted" > Waiting array </param>//< param name= "MaxNumber" > The maximum number in the array to be queued, if specified </param>//<returns></returns> static int[
            ] Pogeon_sort (int[] unsorted, int maxnumber = ten) {int[] Pogeonhole = new Int[maxnumber + 1];
            foreach (var item in unsorted) {pogeonhole[item]++;
            } return pogeonhole; /* * POGEONHOLE[10] = 4;
            The implication is that there are 4 10 occurrences in the array to be queued, the same as 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.WR
                Iteline (i);
    }        } console.readline (); }

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.