#include <list>
#include <iostream>
#include <algorithm>//注意需要这个库
using namespace std;
int main()
{
list<int> l;
for(size_t i=1; i < 11; ++i)
{
l.push_back(i);
}
list<int>::iterator it;
for (it=l.begin(); it!=l.end();++it)
{
cout << *it << " ";
}
cout <<endl;
//采用find()查找算法在链表中查找;
it = find(l.begin(),l.end(),5);
if (it != l.end())
{
cout << "find it" << endl;
}
else
{
cout << "not find it" << endl;
}
cin.get();
return 0;
}
#include <iostream>
#include <algorithm>//注意需要这个库
using namespace std;
int main()
{
list<int> l;
for(size_t i=1; i < 11; ++i)
{
l.push_back(i);
}
list<int>::iterator it;
for (it=l.begin(); it!=l.end();++it)
{
cout << *it << " ";
}
cout <<endl;
//采用find()查找算法在链表中查找;
it = find(l.begin(),l.end(),5);
if (it != l.end())
{
cout << "find it" << endl;
}
else
{
cout << "not find it" << endl;
}
cin.get();
return 0;
}
本文详细介绍了C++链表的基本操作,包括push_back、遍历、使用find算法进行查找,并通过实例展示了链表的应用。
1941

被折叠的 条评论
为什么被折叠?



