Sort radix in c by floating point numbers

Ok, so I need to create a radix collation for unsigned and floating point numbers. My version of unsigned ints works as it should, I have a little problem with the fact that it works for floating point values. It basically sorts the values โ€‹โ€‹of my array into the integer numeric value of the floating point number, but does not sort it based on the decimal value. (Example 36.65234 will appear before 36.02311 if it is the first in an unsorted array) This code segment is where I do my manipulations and masking bits, and I'm sure this is my problem.

/* For loop to create bin */ for(int i=0; i<n; i++){ temp_int = (((unsigned int)(list[i]))>>bitwise)&0xff; bin[temp_int] = bin[temp_int]+1; } /*For loop to get map */ for (int i=0; i<256; i++) { map[i+1] = bin[i]+count; count = map[i+1]; } /* For loop to copy "sorted" values into other array */ for (int i=0; i<n; i++) { temp_int = (((unsigned int)(list[i]))>>bitwise)&0xff; int buf_loc = map[temp_int]; temp_arr[buf_loc] = list[i]; map[temp_int] = map[temp_int]+1; } 

Thanks in advance!

+4
source share
1 answer

Radix sort is a linear sorting algorithm. It can be applied to floating point values.

Look at this:

+5
source

Source: https://habr.com/ru/post/1341730/


All Articles