1 million data, data value between 0~65535, please use as little memory and fastest speed from small to large sort

Source: Internet
Author: User

Scene Description:1 million data, data value between 0~65535, please use as little memory and fastest speed from small to large sort

Voidsort (int* array, int n)

{

The value of n is around 1 million.

Your implementation

}

We first observed that all the data had been saved in array arrays, and what we need to do now is to sort the elements in the array. Now we extract the elements from the array, such as 3, and then we extract the elements of the group subscript is 3, save to the temporary space, the number is calculated by negative numbers:

Void sort (int* array, int n) {    int tmp=0;     for (int i=0;i<n;i++)     {        // If the traversal is currently a negative number, indicating that it is a count value (rather than a sort value), traverse the next         if (array[i]<0)          {             continue;        }         //the number that is traversed, as the position of the subscript, the value is a negative number, indicating that this is a count value,-increase the count value, traverse the next         if (array [array[i]]<0)         {             array[array[i]]--;             continue;        }         //back to the previous value and start the match again &NBsp;       tmp=array[array[i]];         array[array[i]]=-1;        array[i]=tmp;         i--;    }}



1 million data, data value between 0~65535, please use as little memory and fastest speed from small to large sort

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.