我已经实施气泡排序为了排序IntDoublePair。例如:气泡排序不排序 - IntDoublePair
[1 0.5]
[1 0.8]
[1 0.67]
排序为:
[1 0.5]
[1 0.67]
[1 0.8]
当我执行的代码,它给我的数据不会按排序顺序。我很困惑,我哪里错了。我需要一些帮助。
private ArrayList<IntDoubleTextPair> sortCollection(ArrayList<IntDoubleTextPair> collection)
{
for (int current = 0; current < collection.size(); current++)
{
for (int next = 1; next < collection.size(); next++)
{
if (collection.get(current).getFirst().get() >= collection.get(next).getFirst().get())
{
if (collection.get(current).getSecond().get() > collection.get(next).getSecond().get())
{
temp = collection.get(next);
collection.set(next, collection.get(current));
collection.set(current, temp);
}
}
}
}
return collection;
}
仍然没有正确排序。外部和内部循环初始化是否正确? – user1584253 2015-01-09 22:28:23