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