【发布时间】:2016-07-24 17:33:47
【问题描述】:
我有类似的东西:(X - 不同的算法)
public class XAlgorithm{
sort(List l){...}
}
在 testClass 中呈现如下:
ArrayList array = new ArrayList(...); // original array
public static void main(String[]args){
AlgorithmsTest at = new AlgorithmsTest();
at.testInsertSort();
// when add at.array.printAll() - method printing all elements, there are no changes to original array what I want
at.testBubbleSort();
at.testSelectSort();
at.testShellSort();
}
testBubbleSort{
...
ArrayList arrayBubble = new ArrayList(testBubble.sort(array));
...
}
问题是我的结果(由 System.currentTimeMilis() 测量的时间)在我为 ex 启动时不同。连续两次使用相同的算法,这也很奇怪,因为即使我在每个方法中都完成了复制(通过将所有新元素放入新数组然后对其进行操作)仍然工作错误。无论是哪一个,对于 main 中的第一个算法来说,时间总是最长的。
我什至控制了每个算法之间的数组(就像上面代码中的 //comment),这是正确的 - 没有对其进行更改,那么问题出在哪里:/?
提前致谢
【问题讨论】:
-
不幸的是我没有看到任何联系,代码没有那么复杂。
标签: java algorithm implementation