- 1、本文档共12页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 5、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 6、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 7、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 8、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
vector、map容器删除操作总结(Summary of vector and map container deletion operations)
vector、map容器删除操作总结(Summary of vector and map container deletion operations)
1, about the elements in the vector deletion and iterator invalidation
View plaincopy to clipboardprint vectorint VV?;
Vv.push_back (1); / / add the first element
Vectorint: iterator: itBegin = vv.begin (); / / get the first iterator *itBegin=1
Vv.push_back (2); / / for reservation is not enough, so the memory before the move, the iterator will all failure
Vv.push_back (1); / / that is to say, itBegin is now an iterator is invalid
Vv.push_back (1); / / so vector iterator must be failure!
Vv.push_back (3); / / add, insert and delete mobile, reserve, and resize can make the iterator invalid!
Vv.push_back (4);
Vv.push_back (3);
Vv.push_back (5);
Vv.push_back (6);
Int n = vv.size (//n = 9);
Vectorint: iterator: itrmv = remove (vv.begin), vv.end (), (3); / / RESULTS: 1,2,1,1,4,5,6,5,6
N = vv.size (//n = 9);
All the elements of a value equal to the / / delete vector
The //remove algorithm is effective for the elements in the container to move forward covering invalid elements, returns the first element pointer is invalid
//1, it does not have a deletion of 2, not 3, tail invalid elements after the container size constant
Vv.erase (itrmv, vv.end) (1,2,1,1,4,5,6); / / RESULTS:
N = vv.size (//n = 7);
Bool BeDelete (int n)
{
Return n n || = = 1 = = 2;
}
/ / all the elements to meet certain conditions by using remove_if algorithm to delete in vecotr
Vv.erase (remove_if (vv.begin), vv.end (), BeDelete (), vv.end ()); / / RESULTS: 4,5,6
N = vv.size (//n = 3);
If the cycle / / delete, failure to pay attention to the problem after the iterator erase
For (vectorint:: iterator it=vv.begin (it); =vv.end (!);)
{
If (*it = 4)
{
* the wrong way
Vv.erase (it); / / add delete operation before it may be ineffective for vector
It++ //it was invalid;
* /
* the wrong way
Vv.erase (it++); //erase element is shifted so after skipping a it multi elements
* /
It = vv.erase (it); / / the correct approach, erase returns the
您可能关注的文档
- sap2000线性和非线性(SAP2000 linear and nonlinear).doc
- sci论文摘要中常用的表达方法(Expressions commonly used in SCI Abstract).doc
- scp-682(scp-682).doc
- screen实现后台运行程序(Screen implements the background running program).doc
- sdh设备的优势(Advantages of SDH devices).doc
- sdi高清摄像机(SDI HD camera).doc
- sds-page电泳常见问题的分析(Analysis of common problems in SDS-PAGE electrophoresis).doc
- sd卡读写程序(SD card read and write program).doc
- se800常用命令(SE800 common commands).doc
- securdisc摘要(&s)(SecurDisc abstract (&s)).doc
- 2025年吉林省长春市中考历史试题(解析版).pdf
- 2024-2025学年人教版八年级物理下册期末复习练习卷 (含答案).pdf
- 人教版八年级英语上册期末核心考点归纳(含答案).pdf
- 氧化还原滴定与沉淀滴定的相关计算-2024年高考化学考点复习(全国)解析版.pdf
- 数与式一(有理数、实数和代数式,60题)-2021-2025年中考数学复习分类汇编(上海专用).pdf
- 议论文阅读-2024年中考语文一轮复习题型专练.pdf
- 2025年人教版新高一英语学困生专项复习《完形填空》.pdf
- 2023-2025年高考地理试题分类汇编:交通(全国通用)解析版.pdf
- 2025年高考历史试题分类汇编:中国近代史·选择题(全国通用)原卷版.pdf
- 氧化还原滴定与沉淀滴定的相关计算-2024年高考化学考点复习(全国)原卷版.pdf
文档评论(0)