How to make a fast search for an object with a particular value in a vector of structs or classes? c++

前端 未结 4 2016
无人及你
无人及你 2021-01-24 06:38

If I have thousands of struct or class objects in a vector, how to find those that are needed, in a fast way?
For example:
Making a game, and I need fas

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-24 06:58

    A vector is just an unordered collection of objects. There is not really anyway to do what you are asking unless you start sorting your vector in specific ways (e.g. if it is sorted you can jump to the middle of the vector and potentially split your search time in half)

    You may be better off picking a different data structure (either instead of the vector or in combination with it)

提交回复
热议问题