日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

stl list 删除元素_删除所有出现的元素,并从列表中删除一些特定的元素。 C ++ STL...

發(fā)布時間:2025/3/11 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 stl list 删除元素_删除所有出现的元素,并从列表中删除一些特定的元素。 C ++ STL... 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

stl list 刪除元素

list.remove()和list.remove_if()函數(shù) (list.remove() and list.remove_if() functions)

remove() function is used to remove all occurrences of a given element from the list and function remove_if() is used to remove set of some specific elements from the list.

remove()函數(shù)用于從列表中刪除所有出現(xiàn)的給定元素,而remove_if()函數(shù)用于從列表中刪除某些特定元素的集合。

Example:

例:

List elements are11223344551122Element to remove: 11List element after removing 112233445522Condition to remove some specific elements: all ODD numbersList element after removing all ODD numbers224422

Program:

程序:

#include <iostream> #include <list> using namespace std;int main() {//declaring a list list<int> iList = {11, 22, 33, 44, 55, 11, 22};//declaring iterator to the listlist<int>::iterator l_iter;//printing list elementscout<<"List elements are"<<endl;for (l_iter = iList.begin(); l_iter != iList.end(); l_iter++)cout<< *l_iter<<endl;//remove 11 from the ListiList.remove(11);cout<<"List elements after removing 11"<<endl;for (l_iter = iList.begin(); l_iter != iList.end(); l_iter++)cout<< *l_iter<<endl;//remove all ODD numbersiList.remove_if([](int n){return (n%2!=0); });cout<<"List elements after removing all ODD numbers"<<endl;for (l_iter = iList.begin(); l_iter != iList.end(); l_iter++)cout<< *l_iter<<endl;return 0; }

Output

輸出量

List elements are 11 22 33 44 55 11 22 List elements after removing 11 22 33 44 55 22 List elements after removing all ODD numbers 22 44 22

翻譯自: https://www.includehelp.com/stl/remove-all-occurrences-of-an-element-and-remove-set-of-some-specific-from-the-list.aspx

stl list 刪除元素

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎勵來咯,堅持創(chuàng)作打卡瓜分現(xiàn)金大獎

總結

以上是生活随笔為你收集整理的stl list 删除元素_删除所有出现的元素,并从列表中删除一些特定的元素。 C ++ STL...的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。