放牧代码和思想
专注自然语言处理、机器学习算法
    This thing called love. Know I would've. Thrown it all away. Wouldn't hesitate.

CList在遍历的同时删除元素

CList<int, int&>list;
for (int i = 0; i < 10; i++)
{
   list.AddHead(i);
}

DWORD dwLength = list.GetCount();
for (i = 0; i < dwLength;)
{
   POSITION p = list.FindIndex(i);
   int n = list.GetAt(p);
   if (n == 4)
   {
    list.RemoveAt(p);
    dwLength–;
   }
   else
   {
    cout << n << endl;
    i++;
   }
}

评论 欢迎留言

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

我的作品

HanLP自然语言处理包《自然语言处理入门》