#include<bits/stdc++.h>
using namespace std;
//list的详细使用
/**Lists将元素按顺序储存在链表中.
与 向量(vectors)相比, 它允许快速的插入和删除,但是随机访问却比较慢.
**/
list<int> l;
/**
list是链表数组
**/
int main(){
//链表的遍历
for( int i = 0; i < 10; i++ )
//链表后面插入元素
l.push_back( i );
l.insert(--end(l),10000010);
while( !l.empty() ) {
cout << l.front() << endl;
//删除链表前边的元素
l.pop_front();
}
//remove(val)删除所有值为val的元素
/**
void remove_if( UnPred pr );
remove_if()以一元谓词pr为判断元素的依据,遍历整个链表。如果pr返回true则删除该元素。
**/
l.resize(10000,666);
cout<<l.size();
cout<<endl;
return 0;
}
算法c++之stl---list详细使用
最新推荐文章于 2020-12-04 09:01:44 发布