list<Double>计算绝对值并排序

public List<Double> XXX(List<Double> absoluteSortList) {
int size=absoluteSortList.size();
Double[] sort=(Double[])absoluteSortList.toArray(new Double[size]);
//最多做n-1趟排序
for (int i = 0; i < sort.length -1; i++) {
//j的范围是在逐步缩小的
for (int j = 0; j < sort.length - i - 1; j++) {
//把小的值交换到前面
if (Math.abs(sort[j]) > Math.abs(sort[j + 1])) {
Double temp = sort[j];
sort[j] = sort[j + 1];
sort[j + 1] = temp;
}
}
}
absoluteSortList= Arrays.asList(sort);
return absoluteSortList;
}
posted @ 2021-11-13 17:02  努力搬砖的一员  阅读(515)  评论(0)    收藏  举报