# include <iostream>
# include <list>
using namespace std;
void PrintListContents(const list<int> & listInput);
int main(){
list<int> a;
a.push_front(4);
a.push_front(3);
list<int>::iterator iter;
//iter = a.push_front(2);
a.push_front(2);
a.push_back(1);
a.push_front(0);
//PrintListContents(a);
//删除
// iterator erase( iterator pos );
// iterator erase( iterator start, iterator end );
//删除指定的元素
list<int>::iterator it = a.begin();
a.erase(a.begin());
list<int> b;
b.push_front(6);
b.push_front(10);
b.push_front(-1);
//排序
b.sort();
PrintListContents(b);
//反转
b.reverse();
//PrintListContents(b);
return 0;
}
void PrintListContents(const list<int> & listInput){
//不加空间名也可以,因为已经 using namespace std;
list<int>::const_iterator iter;
for(iter=listInput.begin();iter!=listInput.end();iter++){
cout<<*iter<<endl;
}
}
list用法2
最新推荐文章于 2023-02-26 21:25:31 发布