本文主要是介绍2020.7.18 学习心得(C++ forward_list),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
(1) forward_list 的头文件是 #include <forward_list>
以下程序是删除forward_list中元素的程序代码。
严格注意forward_list(单向链表)中是没有emplace,erase,insert操作的
只有emplace_after,erase_after,insert_after
#include <iostream>
#include <forward_list>
using namespace std;
int main(){forward_list<int> f = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};auto pr = f.before_begin();auto it = f.begin();while(it != f.end()){if(*it%2){it = f.erase_after(pr); //pr 得用要删除的元素之前的迭代器}else pr = it++;}for (auto t : f){cout << t << " ";}return 0;
}
这篇关于2020.7.18 学习心得(C++ forward_list)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!