#include<stdio.h> #include<iostream> #include<algorithm> #include<cstring> #include<deque> #include<list> using namespace std; int main() { list<int> l; l.push_back(2);//从后面插入 l.push_back(8); l.push_back(1); l.push_back(5); l.push_back(1); list<int>::iterator it,it2; for(it=l.begin();it!=l.end();it++) { cout<<*it<<" "<<endl; } it=find(l.begin(),l.end(),5);//查找 if(it!=l.end()) { cout<<" find it "<<endl; } else { cout<<"not find it "<<endl; } it=find(l.begin(),l.end(),10);//查找 if(it!=l.end()) { cout<<" find it"<<endl; } else { cout<<" not find it"<<endl; } l.sort();//在里面排序 for(it=l.begin();it!=l.end();it++) { cout<<*it<<" "; } cout<<endl; // l.unique();//去重 l.remove(1);//删除所有值为1的元素。 for(it=l.begin();it!=l.end();it++) { cout<<*it<<" "; } cout<<endl; l.push_front(90);//从前面插入 for(it=l.begin();it!=l.end();it++) { cout<<*it<<" "; } cout<<endl; // l.pop_front();//从前面删除 //l.pop_back();//从后面删除 it=l.begin(); for(int i=1;i<=2;i++)//删除从0开始数的第二个元素 { it++; } l.erase(it); for(it=l.begin();it!=l.end();it++) { cout<<*it<<" "; } return 0; }
关于list
最新推荐文章于 2022-06-28 10:59:05 发布