在c#中ArrayList的排序是比较常见的:
其中有一个PointF数组points,
ArrayList arrayList = new ArrayList();
for (int i = 0; i < points.Length; i++)
{
if(points[i].Y > 0.9f)
arrayList.Add(points[i]);
}
arrayList.Add(points[i]);
//排序
AmplitudeCompare amplitudeCompare =new AmplitudeCompare();
arrayList.Sort(amplitudeCompare);
//排序算法,要继承IComparer
private class AmplitudeCompare : System.Collections.IComparer
{
public int Compare(object x, object y)
{
if ((Math.Abs(((PointF)x).Y) - Math.Abs(((PointF)y).Y)) > 0.0001f)
return 1;
if((Math.Abs(((PointF)x).Y) - Math.Abs(((PointF)y).Y)) <= -0.0001f)
return -1;
else
return 0;
}
}
posted on 2010-06-12 17:48
漂漂 阅读(2991)
评论(0) 编辑 收藏 引用 所属分类:
c#开发