why there is no find for vector in C++

后端 未结 6 908
傲寒
傲寒 2021-02-14 03:13

what\'s the alternative?

Should I write by myself?

6条回答
  •  无人共我
    2021-02-14 03:28

    The reason there is no vector::find is because there is no algorithmic advantage over std::find (std::find is O(N) and in general, you can't do better for vectors).

    But the reason you have map::find is because it can be more efficient (map::find is O(log N) so you would always want to use that over std::find for maps).

提交回复
热议问题