美文网首页
2018-12-24 #STL#

2018-12-24 #STL#

作者: 11bansakana | 来源:发表于2018-12-24 22:49 被阅读0次

C++ vector删除符合条件的元素

两点:algorithm::remove,vector.erase()
cppreference-remove
cppreference-vector-erase
remove 不真的移除元素,它只把元素前移,并返回移除符合条件的元素后应该有的end,真的移除元素,应该在执行remove()后,再执行一次vector.erase

C++ vector去除重复元素

两点:algorithm::unique,algorithm::sort
unique同样不真的移除元素,只是把相同元素合并,所以去重之前要先使用algorithm::sort排序(如果用稳定版请使用stable_sort),再使用unique去重,最后使用erase删除元素

相关文章

网友评论

      本文标题:2018-12-24 #STL#

      本文链接:https://www.haomeiwen.com/subject/iyitlqtx.html