這次要排序的類型更無法想象..是要排序浮點數...
using System;
using System.Collections.Generic;
using System.Text;
namespace WindowsApplication3
...{
public class FloatRadixSortItem : RadixSortItem
...{
float value;
public float Value
...{
get
...{
return value;
}
}
public FloatRadixSortItem(float Value)
...{
value = Value;
if (value < 0)
...{
IsNegative = true;
}
else
...{
IsNegative = false;
}
Data = new byte[4];
byte[] temp = BitConverter.GetBytes(value);
uint bi3 = temp[3];
bi3 <<= 8;
bi3 += temp[2];
bi3 <<= 8;
bi3 += temp[1];
bi3 <<= 8;
bi3 += temp[0];
if (value < 0)
...{
bi3 = ~bi3;
}
uint bi1 = bi3 & 0x7F800000;
Data[3] = (byte)(bi1 >> 23);
bi1 = bi3 & 0x7FFFFF;
Data[0] = (byte)(bi1 & 0xFF);
bi1 >>= 8;
Data[1] = (byte)(bi1 & 0xFF);
bi1 >>= 8;
Data[2] = (byte)(bi1 & 0xFF);
DataLen = 4;
}
public override string ToString()
...{
return value.ToString() + " " + Data[0].ToString("X2")
+" " + Data[1].ToString("X2")
+" " + Data[2].ToString("X2")
+" " + Data[3].ToString("X2");
; }
}
}
痛苦的翻閱了IEEE浮點數的存放格式,然後又痛苦的拆分了這個浮點數終於可以排序了...什麼負浮點數總是從大到小排序的??奇怪的問題..int為什麼沒有問題?啊...負整數存的是反碼?什麼? -1==0XFF FF FF FF ,沒有辦法負浮點數只好求反了..才有這樣的代碼..
if (value < 0)
...{
bi3 = ~bi3;
}待續....