zl程序教程

您现在的位置是:首页 >  后端

当前栏目

C++ list 查找

C++List 查找
2023-09-14 09:07:07 时间
#include <iostream>
#include <list>
#include <algorithm>

using namespace std;


int main()
{
  list<int> list1;
  for (int k=0;k<10;k++)
  {
    list1.push_back(k);
  }

  for (int k=0;k<10;k++)
  {
    list1.insert(list1.end(), k);
  }

  list<int>::iterator list_iter1;
  for (list_iter1 = list1.begin();list_iter1 != list1.end();++list_iter1)
  {
    cout << *list_iter1 << " ";
  }
  cout << endl;

  //find
  list<int>::iterator list_iter2 = find(list1.begin(),list1.end(),2);
  cout << *list_iter2 << endl;

  system("pause");
  return 0;
}