加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 这种排序方法的时间复杂度是多少?

发布时间:2020-12-14 05:24:46 所属栏目:Java 来源:网络整理
导读:我写了这个课程: public class SortingObjectsWithAngleField implements ComparatorPoint { public int compare(Point p1,Point p2) { double delta = p1.getAngle() - p2.getAngle(); if(delta == 0.00001) return 0; return (delta 0.00001) ? 1 : -1; }
我写了这个课程:
public class SortingObjectsWithAngleField implements Comparator<Point> {

    public int compare(Point p1,Point p2) {
        double delta = p1.getAngle() - p2.getAngle();
        if(delta == 0.00001)
            return 0;
        return (delta > 0.00001) ? 1 : -1;
    }
}

然后在我的main()方法中,我创建了一个列表,我添加了一些具有“X”和“angle”字段的对象.然后我用

Collections.sort(list,new SortingObjectsWithAngleField());

我想知道这种排序方式的复杂性是什么?

谢谢

解决方法

您可以阅读集合排序中的文档,但这里是为您而定:

The sorting algorithm is a modified
mergesort (in which the merge is
omitted if the highest element in the
low sublist is less than the lowest
element in the high sublist). This
algorithm offers guaranteed n log(n)
performance.

您的比较器不会改变这种复杂性,除非您对其中的循环执行任何操作,否则您不会.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读