【发布时间】:2014-02-16 01:33:32
【问题描述】:
我看过比较器和算法,但我无法理解它们。来自 java.util.Collections 的比较器。 所以我选择使用这个:
//return an array in descending order, using set algorithm
public int[] descendSort()
{
int[] tempArray = new int[temps.length];
for (int i = temps.length-1; i <= 0; --i)
{
tempArray[i] = temps[i];
}
return tempArray;
}
我在客户端创建的数组是这样的:
int[] temps1 = new int[]{45, 76, 12, 102, 107, 65, 43, 67, 81, 14};
我的输出结果如下:。
The temperatures in descending order is: 0 0 0 0 0 0 0 0 0 0
为什么????
【问题讨论】:
-
这里可以看到Comparator接口的使用方法:stackoverflow.com/questions/7414299/…
-
@HovercraftFullOfEels 我做了一个方法,它事先对数组进行排序,所以这不是问题。