C++ STL(标准模板类) 学习笔记
来源:互联网 发布:java md5加密 编辑:程序博客网 时间:2024/06/05 22:58
Vector 动态数组 迭代器相当于一个指针 对容器的元素进行遍历 vector 的添加和删除在尾部
void testVector(){
vector<int> v1;
v1.push_back(1);
v1.push_back(2);
v1.push_back(3);
v1.front();
/*从后往前输出
while(v1.size()>0)
{
cout<<v1.back();
v1.pop_back();
}
*/
//遍历
for(vector<int>::iterator it=v1.begin();it!=v1.end();it++)
{
cout<<*it;
}
//逆序遍历
for(vector<int>::reverse_iterator it=v1.rbegin();it!=v1.rend();it++)
{
cout<<*it;
}
//修改
// v1.front()=22;
//初始化
vector<int> v2=v1;
vector<int> v3(3,9);
vector<int> v4(v1.begin(),v1.begin()+2);
vector<int> v5(10);
for(int i=0;i<10;i++)
{
v5[i]=i+1;
}
}
==========================================================================
void testVector_1(){
vector<int> v1(10);
for(int i=0;i<10;i++)
{
v1[i]=i+1;
}
//区间删除
v1.erase(v1.begin(),v1.begin()+1);
//指定位置删除
v1.erase(v1.begin()+1);
//根据元素的值删除
for(vector<int>::iterator it=v1.begin();it!=v1.end();)
{
if(*it==2)
it=v1.erase(it);//指针自动下移
}
//插入
v1.insert(v1.begin(),100);
}
====================================================
/*
双端数组deque 从头部插入 删除
从尾部插入删除
*/
void testDeque(){
deque<int> d1;
d1.push_front(1);
d1.push_front(2);
d1.push_front(3);
d1.push_back(3);
d1.push_back(2);
d1.push_back(1);
for(int i=0;i<d1.size();i++)
{
cout<<d1[i]<<" ";
}
//弹出
d1.pop_back();
d1.pop_front();
//查找 -
deque<int>::iterator it=find(d1.begin(),d1.end(),3);
if(it!=d1.end)
{
cout<<"找到了";
}
}
================================================================
/*
栈
*/
void testStack(){
stack<int> st;
st.push(1);
st.push(2);
st.push(3);
while(!st.empty())
{
cout<<st.top();
st.pop();
}
}
==========================================================
//队列
void testQueu(){
queue<int> q;
q.push(1);
q.push(2);
q.push(3);
q.front();//队头
q.back();//对尾
while(!q.empty())
{
cout<<q.front();
q.pop();
}
}
- C++ STL(标准模板类) 学习笔记
- C/C++学习笔记(十)标准模板库STL和string
- C++:标准模板库(STL)
- C++STL标准模板库
- 标准模板库(STL)学习笔记之List容器
- 【学习笔记】C++高级程序设计:STL标准模板库
- C++学习笔记(五)标准模板库STL
- 【STL 学习笔记】标准模板库介绍及相关链接
- 【学习笔记】解析STL(标准模板库)
- 学习标准模板库STL
- C++标准程序库 学习笔记 第五章 STL(标准模板库概述)
- C++:STL(标准模板库)
- C++_标准模板库(STL)
- 笔记:标准模板库(STL)
- stl标准库学习笔记
- [转]一步一步学习STL标准模板库
- 标准模板库(STL)学习探究-------前言
- 轻轻松松学习C++ 标准模板库STL
- hadoop、hbase、hive等版本对应关系
- Featherstone R. Rigid body dynamics algorithms page 9
- nginx之平滑升级详解
- MongoDB Shell使用
- [Leetcode] Integer to Roman
- C++ STL(标准模板类) 学习笔记
- bzoj3012 [Usaco2012 Dec]First!
- 求同一号码一天内的上网流量
- leetcode 3Longest Substring Without Repeating Characters
- UI07_导航视图控制器
- 怎么修改PDF文件中的文字
- 访问Web Service(第二讲)
- android自定义view——温度计
- ios学习--TableView详细解释