c++ list remove_if的用法

2025-03-14 03:00:54

1、创建新的空白工程,工程中新建listTest类。添加main函数。

c++ list remove_if的用法

2、给listTest类添加init方法和list<挢旗扦渌;int>对象init方法主要主要用于实现list结构的初始化,在结构中添加0,1,2,3,4,5,6,7,8,9是个数

c++ list remove_if的用法

3、打印删除前list结构中的数据,如下图所示

c++ list remove_if的用法
c++ list remove_if的用法

4、添加删除条件函数,这里我们删除结构中的所有奇数。

c++ list remove_if的用法

5、编写代码,使用判断条件,删除结构中的奇数。调用remove_if完成。

c++ list remove_if的用法

6、删除结果打印如下图所示

c++ list remove_if的用法
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢