随笔 - 224  文章 - 41  trackbacks - 0
<2010年6月>
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

享受编程

常用链接

留言簿(11)

随笔分类(159)

随笔档案(224)

文章分类(2)

文章档案(4)

经典c++博客

搜索

  •  

最新评论

阅读排行榜

评论排行榜

在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 漂漂 阅读(2951) 评论(0)  编辑 收藏 引用 所属分类: c#开发

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理