list容器的erase函数和remove函数

由于list容器的特殊实现,所以list容器实现了自己的erase函数和remove函数。

erase函数的函数声明:

可以看到函数的参数是由迭代器给出的。由迭代器给出删除的位置或者区间。

    1) Removes from the list container either a single element (position) or a range of elements ([first,last)).

    2) This effectively reduces the container size by the number of elements removed, which are destroyed.

remove函数的函数声明

可以看出,参数不是迭代器类型的,而是value_type类型的,目的是为了删除容器中的特定值。

1)  Removes from the container all the elements that compare equal to val. This calls the destructor of these objects and reduces the container size by the number of elements removed.

2)  Unlike member function list::erase, which erases elements by their position (using an iterator), this function (list::remove) removes elements by their value.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值