【发布时间】:2018-09-10 21:01:35
【问题描述】:
好的,所以我有两个 ArrayList。第一个数组列表从末尾开始,并尝试从我的第二个开始添加项目,第二个从头开始。我必须列出迭代器,其概念是将项目添加到第一个列表中,直到达到最大容量,然后我继续将新项目添加到第一个列表的第二个项目中,依此类推。问题是当我尝试从第二个列表中删除一个项目时,该列表不会重新排序,并且某些项目不会被检查。代码如下:
public void loadFromBeh(ArrayList<Cargo> storage) {
ListIterator<Wagon> waIterator = wagons.listIterator(wagons.size());
ListIterator<Cargo> stIterator = storage.listIterator();
while (waIterator.hasPrevious()) {
Wagon w = waIterator.previous();
while (stIterator.hasNext()) {
Cargo c = stIterator.next();
System.out.println("pr " + w.current_weight);
if (c.weight <= w.max_weight) {
if (w.current_weight == 0) {
w.current_weight = c.weight;
System.out.println("first " + w.current_weight);
stIterator.remove();
} else {
w.current_weight = w.current_weight + c.weight;
System.out.println("new current " + w.current_weight);
if (w.current_weight <= w.max_weight) {
w.cargos.add(c);
stIterator.remove();
System.out.println("ok " + w.current_weight);
}
}
}
}
}
}
【问题讨论】:
标签: java