What data structure would be best for this?

For my game, when an object enters the sensor, I need to add it to the list, and when the object leaves the sensor, it needs to be removed from this list. I also need to quickly find this object.

So essentially:

I need to do this: quick add, quick delete and quick search.

What data structure would be better for this, given that at any given time the structure would have about 10 objects.

thank

+5
source share
4 answers

With 10 objects, something will do ( std::vector, dequeor set), and no one will be able to determine which one works best before profiling.

, , , , std::set . , , std::find(v.begin(), v.end(), sensor), s.find(sensor).

std::list, , . ++ ( - , - ). ( ). list, , . set.

+9

std::list, .

+1

, , , ! , , , , , . , , .

- .

0

, Linked List . , .

0

All Articles