C ++中partition()和remove()函数之间的区别 [英] Difference between partition() and remove() functions in C++

查看:592
本文介绍了C ++中partition()和remove()函数之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++中的 partition() remove()之间有什么区别?

What is the difference between the partition() and remove() functions in C++?

remove实际上并不移除容器的任何元素,而是将removed元素放在元素序列的开头,而partition也做同样的事情。

The remove doesn't actually remove any elements of the containers but puts the 'removed' elements at the beginning of the sequence of elements and partition does the same thing as well.

推荐答案


remove [...]将'removed'元素放在序列的开头

remove [...] puts the 'removed' elements at the beginning of the sequence

什么? 。 remove_if 分区首先放置good元素。 分区在后面放置坏元素,而 remove_if 不指定它之后 - 它可能坏元素,但它也可能是任何(好的或坏的)元素的副本。

What? No. Both remove_if and partition put the "good" elements first. partition puts the "bad" elements after that, whereas remove_if does not specify what comes after it -- it might be the bad elements, but it might also be copies of any (either good or bad) elements.

例如,如果 c $ c> 1 2 3 4 5 on 甚至,你可能会得到2 4 5 3 1(注意每个元素只出现一次),而如果你 remove_if 元素,您可能会得到2 4 3 4 5(注意重复项)。

For example, if you partition 1 2 3 4 5 on even, you might get 2 4 5 3 1 (note that each element occurs exactly once), whereas if you remove_if the odd elements, you might get 2 4 3 4 5 (note the duplicates).

这篇关于C ++中partition()和remove()函数之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆