STL之list基本使用实例
来源:互联网 发布:二甲医院 上海知乎 编辑:程序博客网 时间:2024/05/06 16:25
list其实就是双向链表,好好复习list的使用。
Cplusplus描述的list方法:
基本操作实例:
void test_list(){list<int> pList;cout << "push_back() , pop_back() ,begin() , end()测试:" << endl;pList.push_back(1); //尾插pList.push_back(2);pList.push_back(3);pList.push_back(4);pList.push_back(5);cout <<*( pList.begin() ) << endl;cout << (pList.back()) << endl; // end()返回最后一个元素后面的迭代器pList.pop_back(); //尾删cout << *(pList.begin()) << endl;cout << (pList.back()) << endl;pList.pop_front(); //头删cout << *(pList.begin()) << endl;cout << (pList.back()) << endl;cout << "rbegin() , rend() 测试 : " << endl;cout <<*( pList.rbegin() )<<endl; //rbegin()返回end()-1的位置 //rend() 返回begin()-1的位置cout << "front() , back() 测试 : " << endl; //返回的是引用cout << pList.front() << "~~~" << pList.back() << endl;cout << "push_front() , pop_front() 测试 : " << endl; //前插,前删 cout << *(pList.begin()) << endl;pList.push_front(11);cout << *(pList.begin()) << endl;pList.pop_front();cout << *(pList.begin()) << endl;cout << " insert() , erase() , iterator ,empty() 测试 : " << endl;list<int>::iterator it = pList.begin();pList.insert(it, 8);for (it = pList.begin(); it != pList.end(); ++it){cout << *it << " ";}cout << endl;for (it = pList.begin(); it != pList.end(); ) //查看是否迭代器会失效{it = pList.erase(it ); //必须接受erase的返回值,否则出错咯}cout << pList.empty() << endl;pList.push_back(5);pList.push_back(3);pList.push_back(1);pList.push_back(7);pList.push_back(3);cout << "sort() , unique() , remove() , splice()"<< endl;pList.sort(); //排序for (it = pList.begin(); it != pList.end(); ++it){cout << *it << " ";}cout << endl;pList.unique(); //去重!for (it = pList.begin(); it != pList.end(); ++it){cout << *it << " ";}cout << endl;pList.remove(7); //移除具体的内容for (it = pList.begin(); it != pList.end(); ++it){cout << *it << " ";}cout << endl;it = pList.begin();//pList.splice //现list拼接的功能。将源list的内容部分或全部元素删除,拼插入到目的listlist<int> list1;list1.push_back(0);list1.push_back(2);list1.push_back(4);pList.splice(it, list1);for (it = pList.begin(); it != pList.end(); ++it){cout << *it << " ";}cout << endl;cout<< list1.empty() << endl;}
0 0
- STL之list基本使用实例
- STL之vector基本使用实例
- STL之set、map基本使用实例
- STL List 的基本使用
- stl之list使用
- STL之LIST使用
- STL之LIST使用
- C++ STL之list入门实例
- STL之vector和list的实例
- STL list基本实现
- 使用STL之list实现链表逆置
- stl之二: list使用总结【转】
- STL之set的基本使用
- STL之map的基本使用
- C++之STL基本容器的使用
- STL学习之list
- STL之list模板
- STL之list学习
- [实验二] 单链表的基本操作
- ubuntu的recovery模式
- Spark Streaming:性能调优
- 08CMS之数据库操作
- 移动端点击(click)事件延迟问题的产生与解决方法
- STL之list基本使用实例
- 编写程序,实现顺序栈的创建、进栈和出栈等基本操作算法。
- Tinker热修复server端tinkerPatch的接入
- hashMap在类加载时候赋值取值bug记录
- computer-database 项目性能测试执行
- spring 定时任务
- 解决IntelliJ IDEA下github访问速度的问题(从此告别github速度慢的问题)
- OSAL操作系统实验学习笔记04
- Look into "A Neural Network in 11 lines of Python"