比较器接口的覆盖比较方法使用什么排序算法? [英] What sorting algorithm used while overriding compare method of comparator interface?

查看:136
本文介绍了比较器接口的覆盖比较方法使用什么排序算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 Collections.sort(ar, new Comparator<Intervals>() {
                      @Override
                        public int compare(Intervals o1, Intervals o2) {                
                                return (Integer.valueOf(o1.getEnd()))
                                        .compareTo(Integer.valueOf(o2.getEnd()));
                        }
                    });

大家好,我在java中有上面的代码。这里,ar是一个列表,Intervals是一个包含2个整数变量的类:Start和End。我想知道当我们覆盖Comparator接口的compare方法时,遵循什么排序算法。我知道,默认情况下Collections.sort()和Arrays.sort()使用Timsort算法。任何帮助将不胜感激。非常感谢提前。

Hi all, I have the above code in java. Here, ar is a list and Intervals is a class with 2 integer variables : Start and End. I wanted to know what sorting algorithm is followed when we override the compare method of Comparator interface as above. I know, by default Collections.sort() and Arrays.sort() use Timsort algorithm. Any help will be appreciated. Thanks a lot in advance.

推荐答案

Collections.sort()使用 Timsort

Collections.sort() uses a variation of Timsort.

来自 javadocs


该实现改编自Tim Peters的Python
(TimSort)列表排序。它使用了Peter McIlroy的乐观排序
和信息理论复杂性中的技术,参见了第四届
年度ACM-SIAM离散算法研讨会论文集,第467-474页,1993年1月
。 / p>

The implementation was adapted from Tim Peters's list sort for Python ( TimSort). It uses techiques from Peter McIlroy's "Optimistic Sorting and Information Theoretic Complexity", in Proceedings of the Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474, January 1993.

请注意 Collections.sort()算法获取黑匣子比较器,并使用它为每次比较产生的值 - 无需关心比较器幕后的情况。

Note that the Collections.sort() algorithms gets a "black box" comparator, and uses the value it yields for each compare - without caring what is going on behind the scenes of the comparator.

这篇关于比较器接口的覆盖比较方法使用什么排序算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆