C # implements Pigeon Nest sorting

Source: Internet
Author: User

        /// <summary>        ///Pigeon Nest Sort///creates an array of tokens with a length greater than or equal to the maximum value in the array of arrays of sorts, Mark,///maps the number of element values in the array to the Mark array. ///that is, the element value in array arrays corresponds to the index of the mark Array,///the number of occurrences in the array array corresponds to the value of the Mark array index. ///The index value and the number of the mark element (not equal to 0) are then placed in the array in turn. /// </summary>        /// <param name= "Array" >Array to sort</param>        /// <param name= "Maxvalueinarray" >the maximum element value in an array of arrays</param>         Public voidPigeonholesort (int[] Array,intMaxvalueinarray) {            int[] Mark =New int[Maxvalueinarray +1];  for(inti =0; I < array. Length; i++)            {                ///to mark the number of occurrences of an element in an arraymark[array[i]]++; }            intArrayindex =0; ///re-assign to array             for(inti =0; I < mark. Length; i++)            {                ///The number of occurrences of I, starting with the array minimum element value I                 for(intj =0; J < Mark[i]; J + +)                {                    ///updates the elements of an array of arrays to the minimum I and the number of Jarray[arrayindex++] =i; }            }        }        /// <summary>        ///gets the maximum element value in an array of arrays/// </summary>        /// <param name= "Array" >Array</param>        /// <returns>Maximum element value</returns>         Public intMax (int[] Array) {            intmax =-1; foreach(intIteminchArray)if(Item >max) Max=item; returnMax; }

Worst time complexity: O (N+n)
Best time complexity: O (N+n)
Average time complexity: O (N+n)
Worst spatial complexity: O (N*n)

C # implements Pigeon Nest sorting

Related Article

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.