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

前端 未结 4 2015
无人及你
无人及你 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:57

    You should sort your vector and then use the standard library algorithms like binary_search, lower_bound, or upper_bound.

    The above will give you a better compliexity than o(n) given by walk through of entire vector or by using standard library algorithm find.

提交回复
热议问题