我将如何完成以下任务?
List A is a series of
Foo
s, list B is a series ofdouble
s representing time remaining until theFoo
at thei
th position of List A is removed. That is, if a double in List B is less than zero, theFoo
at the same position in List A as the less than zero double in List B is removed from List A and then the less-than-zero double is removed from List B.
List A:
A B C D E
List B (in seconds):
1.0 0.33 0.0 5.0 0.01
//1 tick of 0.33 seconds
List B:
0.67 0.0 -0.33 4.67 -0.32
//Remove offending List A elements based on state of List B
List A:
A B D
//Remove invalid List B elements
List B:
0.67 0.0 4.67
我正在考虑针对列表 B 的 std::remove_if
思路,但是如果我这样做,我将如何删除列表 A 的项目?遗憾的是,不同列表的迭代器不兼容,除了使用手动实现之外,没有办法遍历列表并知道每个值的索引。
最佳答案
您可能要考虑使用结构列表而不是两个列表。然后你可以使用 remove_if 和其他列表函数。
关于c++ - 并行 std::lists,根据列表 B 中项目的状态删除列表 A 中的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16128464/