Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
662 views
in Technique[技术] by (71.8m points)

algorithm - Radix Sort, Sorting a float data

Is radix sort capable of sorting float data for example 0.5, 0.9, 1.02, etc.?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...