问题描述
时的基数排序能分拣浮点数据,例如0.5,0.9,1.02,等。?
Is radix sort capable of sorting float data for example 0.5, 0.9, 1.02, etc.?
推荐答案
是的,这是可能的。它需要一个额外的传球,正确处理负值。通过皮埃尔Terdiman 的文章和的详细讨论如何实现它。总之,您将浮子无符号整数,对它们进行排序,然后将其转换回浮动(这是必需的,否则底片值会后积极的正确排序)。
Yes, it is possible. It requires an additional pass to correctly handle negative values. The articles by Pierre Terdiman and Michael Herf discuss in detail how to implement it. In short, you convert the float to unsigned integer, sort them, and then convert them back to float (this is required, otherwise the negatives values would be incorrectly sorted after the positive ones).
他们的方法有,你没有引入任何错误到您的数据优势(前提是你的处理器存储的浮子按照以IEEE 754标准)。
Their method has the advantage that you do not introduce any error into your data (provided that your processor stores the float in accordance to the IEEE 754 standard).
这篇关于基数排序,排序的浮点数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!