mik*_*ike 4 c floating-point radix-sort
好的,所以我必须为无符号整数和浮点数创建基数排序.我的无符号整数版本可以正常工作,但我在使浮点值工作时遇到了一些麻烦.基本上,它按浮点数的整数值对数组的值进行排序,但不会根据小数值对其进行排序.(例如36.65234将出现在36.02311之前,如果它出现在未排序的数组中)这个代码段是我进行操作和屏蔽的地方,我很确定我的问题出在哪里.
/* 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;
}
Run Code Online (Sandbox Code Playgroud)
提前致谢!