Sort buckets (C #)

Source: Internet
Author: User
Sort buckets (C #)

Code implementation:

/// <Summary> <br/> // sort buckets <br/> /// </Summary> <br/> /// <Param name = "arraytosort"> array to be sorted (the elements of this array are in [0-1 )) </param> <br/> // <returns> sorted result </returns> <br/> Public static double [] bucketsort (double [] arraytosort) <br/>{< br/> // bucket <br/> lifecycle list <double> [] bucket = new lifecycle list <double> [10]; <br/> // initialize the bucket <br/> for (INT I = 0; I <10; I ++) <br/>{< br/> bucket [I] = new region list <double> (); <br/>}</P> <p> // bind elements to each bucket <br/> for (INT I = 0; I <arraytosort. length; I ++) <br/>{< br/> int bucketindex = (INT) (arraytosort [I] * 10d ); </P> <p> // Add and sort inserts <br/> inserttolinklist (bucket [bucketindex], arraytosort [I]); <br/>}</P> <p> // sort buckets <br/> int Index = 0; <br/> for (INT I = 0; I <10; I ++) <br/> {<br/> foreach (VAR item in bucket [I]) <br/>{< br/> arraytosort [index ++] = item; <br/>}</P> <p> return arraytosort; <br/>}</P> <p> // <summary> <br/> // insert data in ascending order <br/> /// </Summary> <br/> /// <Param name = "Sort list"> linked list to be sorted </param> <br/> /// <Param name = "num"> insert sorted number </param> <br/> Private Static void inserttolinklist (sorted list <double> sorted list, double num) <br/>{< br/> If (returns list. count = 0) <br/>{< br/> history list. addfirst (Num); <br/> return; <br/>}</P> <p> for (INT I = struct list. count-1; I> = 0; I --) <br/>{< br/> If (else list. elementat (I) <= num) <br/>{< br/> define listnode <double> node = shortlist. findlast (sorted list. elementat (I); <br/> sort list. addafter (node, num); <br/>}< br/>}

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.