Why does vector not have sort() method as a member function of vector, while list does?

前端 未结 6 1472
感动是毒
感动是毒 2021-01-11 09:29

There is a sort() method for lists in STL. Which is absurd, because I would be more inclined to sort an array/vector. Why isn\'t sort() provided for vector? Is there some un

6条回答
  •  孤城傲影
    2021-01-11 10:20

    A vector-specific sort would provide no advantage over std::sort from . However, std::list provides its own sort because it can use the special knowledge of how list is implemented to sort items by manipulating the links instead of copying objects.

提交回复
热议问题