On the container's In the case of In the case of This can not be done because the vectors are not ordered. There is no other way to find an element in a random vector than with a linear search with O (n) complexity. On the other hand, the sequence container is a you think that you need to pass with std :: pair, which is the value_type of the std :: map. Usually you want to search for a key or mapped element, it does not seem very useful. In fact, here you should use the In general, when a container exposes a member function with a member similar to a normal algorithm, this is because the member function does the same thing, but provides better complexity guarantee < / P> what about the other containers such as studs :: list or std :: set or std :: unordered_set simply using
std :: find of C ++ 11 There is no benefit for
method
std :: vector (which has no
search
std :: find uses some smart algorithm or simply the simple way to hover over each element Std :: map It looks like you need to pass with a
std :: pair , which is the
standard_type < / Code> of
std :: map code. Usually you want to search for a key or a mapped element, it does not seem very useful. < Li>
std :: list or
std :: set or
std :: unordered_set ? < / Ul>
search () member Do not offer jobs, so you can not use it. In the case of Std :: map in
find member job, which guarantees better complexity (O (log n)).
std :: vector ,
std :: list is not a sorted container - hence the same conclusion applies Land.
std :: set and
Std :: unordered_set , instead, you should use the
find () member function Those who guarantee better complexity (O (log n) and average o (1) respectively).
No comments:
Post a Comment