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" >array to be queued</param> /// <param name= "MaxNumber" >the maximum number in the array to be queued, if specified</param> /// <returns></returns> Static int[] Pogeon_sort (int[] unsorted,intMaxNumber =Ten) { int[] Pogeonhole =New int[MaxNumber +1]; foreach(varIteminchunsorted) {Pogeonhole[item]++; } returnPogeonhole; /** POGEONHOLE[10] = 4; The implication is that * there are 4 10 occurrences in the array to be queued, the same as other*/ } Static voidMain (string[] args) { int[] x = { About, $, -, -, -, -, About, the, the, -, the, the, to, -, - }; varsorted = Pogeon_sort (x, About); for(inti =0; I < sorted. Length; i++) { for(intj =0; J < Sorted[i]; J + +) {Console.WriteLine (i); }} console.readline (); }
Classic sort algorithm-pigeon nest sort pigeonhole