现在的位置: 首页 > 综合 > 正文

list 中删除满足某个条件的所有记录

2019年01月10日 ⁄ 综合 ⁄ 共 387字 ⁄ 字号 评论关闭
#include "stdafx.h"
#include "Singlelist.h"
#include <list>
using namespace std;

typedef list<int> LIST;
typedef LIST::iterator ITERATOR;


int _tmain(int argc, _TCHAR* argv[])
{
	
	LIST mylist;


	for(int i=0; i<10; i++)
	{
		mylist.push_back(i);
	}
	
	ITERATOR LI;
	for(LI = mylist.begin(); LI != mylist.end();)
	{
		if (((*LI) % 2) !=0)
		{
			
			LI = mylist.erase(LI);
		}
		else
		{
			LI++;
		}
	}

	for(LI = mylist.begin(); LI != mylist.end(); LI++)
	{
		printf("%d\n", *LI);
	}
	getchar();

}

抱歉!评论已关闭.