标准模板库(STL)
来源:互联网 发布:乐乎城市青年公寓黄村 编辑:程序博客网 时间:2024/05/22 17:55
标准模板库(STL)
以矢量vector为例,如下程序是begin()、end()、push_back、pop_back()、erase()、insert()、sort()的用法:
#include <iostream>#include <algorithm>#include <cstdlib>#include <vector>using namespace std;vector <int>::iterator p;void show(vector <int> &a){ for(p=a.begin();p!=a.end();p++) cout<<*p<<' '; cout<<endl<<endl;}bool cmp(int a,int b){ return a>b;}int main(){ vector <int> sb; p=sb.begin(); int i; cout<<"Create the list , 0 to finish:"<<endl; while(cin>>i&&i) { sb.push_back(i); p++; } show(sb); cout<<"Push_back a price :"<<endl; cin>>i; sb.push_back(i); show(sb); cout<<"Delete the last one :"<<endl; sb.pop_back(); show(sb); cout<<"The reserve order sort:"<<endl; sort(sb.begin(),sb.end(),cmp); show(sb); cout<<"Erase:"<<endl;//delete a interval of 3th to 5th sb.erase(sb.begin()+2,sb.begin()+5); show(sb); cout<<"Insert:"<<endl;//insert a interval of first to 3rd itself sb.insert(sb.begin(),sb.begin()+3,sb.begin()+6); show(sb); cout<<"The size of sb: "<<sb.size()<<endl; return 0;}
阅读全文
0 0
- STL(标准模板库)
- Stl(标准模板库)
- 标准模板库(STL)
- 标准模板库(STL)
- STL标准模板库
- STL标准模板库
- STL标准模板库
- STL标准模板库
- STL 标准模板库
- 标准模板库 (STL)
- STL标准模板库
- 标准模板库-STL
- STL 标准模板库
- 标准模板库STL
- STL标准模板库
- STL 标准模板库
- 标准模板库STL
- STL 标准模板库
- 虚拟路径和绝对路径
- 安装Markdown Pad for windows
- Android EditText与Button和Button点击出现的Dialog联动问题
- React Native运行第一个程序
- jsp
- 标准模板库(STL)
- Android网络请求框架使用 -- OkHttp
- ubuntu 1604 搭建samba服务器
- SGISTL源码探究-STL中的红黑树(上)
- Guava
- 多次进行dfs没有对辅助数据结构进行重新赋初始值
- 版本更新
- Linux中断机制
- JAVA学习笔记-----可见性(synchronized/volatile)