特点就是个双向链表
基本操作
// // main.cpp // use_stl_list // // Created by bikang on 16/10/28. // Copyright (c) 2016年 bikang. All rights reserved. // #include#include using namespace std; void tlist(); bool sortFunc(const int &a,const int &b); int main(int argc, const char * argv[]) { // insert code here... tlist(); return 0; } void tlist(){ //创建 std::list
l1; //插入 l1.push_front(11); l1.push_front(21); l1.push_back(3); //大小 cout << l1.size()< ::iterator elem; for(elem=l1.begin();elem!=l1.end();++elem){ cout << *elem <<","; } cout << endl; //其他插入 list l2; l2.push_back(1111); l2.insert(l2.begin(), l1.begin(),l1.end()); //删除 l2.erase(l2.begin()); //范围删除 //l2.erase(l2.begin(),l2.end()); l2.push_back(21); for(elem=l2.begin();elem!=l2.end();++elem){ cout << *elem <<","; } cout << endl; //反转 l2.reverse(); for(elem=l2.begin();elem!=l2.end();++elem){ cout << *elem <<","; } cout << endl; //排序 l2.sort(); for(elem=l2.begin();elem!=l2.end();++elem){ cout << *elem <<","; } cout << endl; //根据排序函数排序 l2.sort(sortFunc); for(elem=l2.begin();elem!=l2.end();++elem){ cout << *elem <<","; } cout << endl; } bool sortFunc(const int &a,const int &b){ return (a > b); }