【发布时间】:2013-11-21 13:23:49
【问题描述】:
我得到了一个包含一些 Tree 节点的列表,并且想要对其进行排序。作为比较器,我使用列表中每个节点都拥有的双变量。
这是我的代码:
List<TreeNode<String>> list = inputNode.getChildren();
for(TreeNode<String> childNode : list)
{
Collections.sort(list, childNode.costs);
}
TreeNode 是这样定义的:
public class TreeNode<T> {
public T data;
public double costs;
public List<TreeNode<T>> children;
// Bunch of getters and setters
}
我要做的是对子节点列表进行排序(降序)。我不想写已经存在的新东西。那为什么我不能使用Collections.sort?
Collections.sortdouble 不是可比较的数据类型吗?
【问题讨论】:
标签: java sorting collections nodes