首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在TimSort方法中调用什么方法?

在TimSort方法中调用什么方法?
EN

Stack Overflow用户
提问于 2011-05-03 07:17:35
回答 1查看 408关注 0票数 1

TimSort是一种在Java7中默认使用的排序算法。

我找到了这个源码,但我不知道该调用哪个方法,因为它们都是私有的。有人能理解吗?谢谢。

http://cr.openjdk.java.net/~martin/webrevs/openjdk7/timsort/raw_files/new/src/share/classes/java/util/TimSort.java

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-03 07:20:09

你不会给任何东西打电话。

它有对java.util来说是包私有的排序方法。当您调用Arrays.sort()函数或类似的函数时,让它调用它们。

评论清楚地表明了这一点:

代码语言:javascript
复制
/*
 * The next two methods (which are package private and static) constitute
 * the entire API of this class.  Each of these methods obeys the contract
 * of the public method with the same signature in java.util.Arrays.
 */

static <T> void sort(T[] a, Comparator<? super T> c) {
    sort(a, 0, a.length, c);
}

static <T> void sort(T[] a, int lo, int hi, Comparator<? super T> c) {
    ...
}

根据我上一条评论的时间判断,这花了不到15分钟的时间:

  • http://pastebin.com/VNyUutiD - SortTest.java
  • http://pastebin.com/deGAfWZj - TimSort.java

结果是:

代码语言:javascript
复制
C:\Documents and Settings\glowcoder\My Documents>java SortTest
Time for default: 4094ms
Time for timsort: 3813ms

C:\Documents and Settings\glowcoder\My Documents>
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5863509

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档