【发布时间】:2011-10-16 03:00:43
【问题描述】:
我反复将 10000 个排序列表合并为一个长排序列表。每个列表包含大约 5000 个doubles。
double[] result;// this is the single long sorted list
void merge(double[] x){
double[] newList=new double[x.length+result.length];
int i=0,j=0;
while(i<x.length && j<result.length){
insert the smaller one
increment i or j;
}
if(i<x.length){
add the rest
}
if(j<result.length){
add the rest
}
result=newList;
}
此方法每次都分配一个新数组。随着result[] 的增长,这不是有效的。有什么建议吗?
【问题讨论】: