//vector的使用
//相当于数组,常用的 添加 删除 清空 测长 操作 #include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
int main()
{
vector<int>a;
a.clear();//清空
for(int i=;i<;i++)
{
a.push_back(i);//把元素i放到a里
}
for(int i=;i<a.size();i++)//a.size()测量a的元素个数
printf("%d ",a[i]);
puts("");
vector<int>::iterator it;//vector容器指针
it=a.begin();//指向第一个元素
a.erase(it+);//删除第三个
for(int i=;i<a.size();i++)
printf("%d ",a[i]);
system("pause");
} //map的使用
//对杂乱无序的字符串或数字 做哈希匹配,可以重新编号,输入一些英文名字,给它们编号
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;
int main()
{
map<string,int>mp;
mp.clear();//清空
string nm[]={"abc","david","lucy","abc","app","lucy"};
int index=;
for(int i=;i<;i++)
{
if(mp[nm[i]]==)
mp[nm[i]]=index++;//判断是否已经出现过,没出现过,就编号
}
map<string,int>::iterator it;//map容器的指针
for(it=mp.begin();it!=mp.end();it++)
{
cout<<it->first<<" "<<it->second<<endl;//按字典序输出每个的编号
}
system("pause");
} //set的使用
//set可以插入很多值,去掉重复元素,并可以查找
#include<iostream>
#include<cstdio>
#include<string>
#include<set>
using namespace std;
int main()
{
set<string>st;
st.clear();//清空
string nm[]={"abc","david","lucy","abc","app","lucy"};
for(int i=;i<;i++)
st.insert(nm[i]);// st里插入元素
set<string>::iterator it;//set容器里的指针
for(it=st.begin();it!=st.end();it++)
{
cout<<*it<<endl;
}
it=st.find("app");
if(it!=st.end())
cout<<"find"<<" "<<"app"<<endl;//找到了就输出 find
else
cout<<"can't find"<<" "<<"app"<<endl;//找不到就输出 can't find
system("pause");
} //stack的使用
//stack几个主要函数
//empty()堆栈为空则返回真
//pop()移除 栈顶元素(不会返回栈顶元素的值)
//push()在栈顶增加元素
//size()返回栈中元素数目
//top()返回栈顶元素
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
using namespace std;
int main()
{
int a[]={,,,,,};
stack<int>st;
int i;
if(st.empty())
{
for(i=;i<;i++)
st.push(a[i]);
}
for(int i=;i<;i++)
{
printf("%d",st.top());
st.pop();
}
printf("\n");
for(int i=;i<;i++)
st.push(a[i]);
printf("The size of stack is %d\n",st.size());
int n=st.size();
for(int i=;i<n;i++)
{
printf("%d",st.top());
st.pop();
}
printf("\n");
system("pause");
} //queue的使用
//queue几个主要函数
//empty()队列为空则返回真
//pop()移除队首元素
//push()在队尾增加元素
//size()返回队列元素数目
//front()返回队首元素
//back()返回队尾元素
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
using namespace std;
int main()
{
int a[]={,,,,,};
queue<int>qu;
int i;
if(qu.empty())
{
for(i=;i<;i++)
qu.push(a[i]);
}
printf("Front is %d and Back is %d\n",qu.front(),qu.back());
for(int i=;i<;i++)
{
qu.pop();
printf("Front is %d and Back is %d\n",qu.front(),qu.back());
}
for(int i=;i<;i++)
qu.push(a[i]);
printf("The size of queue is %d\n",qu.front(),qu.back());
int n=qu.size();
printf("Front is %d and Back id %d\n",qu.front(),qu.back());
for(int i=;i<n-;i++)
{
qu.pop();
printf("Front is %d and Back is %d\n",qu.front(),qu.back());
}
system("pause");
}
//deque 双向队列
//可以在尾部或首部 插入元素
//size()双端队列的长度
//empty()测试双端队列 是否为空
//capacity()双端队列的容量
//front()返回双端队列对首元素
//back()返回 双端队列对尾元素
//push_front()双端队列队首插入元素
//pop_front()删除双端队列队首元素
//push_back()双端队列队尾插入元素
//pop_back()删除双端队列队尾元素
//begin()指向双端队列队首的迭代器
//end()指向双端队列队尾的下一个元素的迭代器 //用数组方式访问deque元素
#include<deque>
#include<iostream>
using namespace std;
int main()
{
deque<int>d;
d.push_back();//双端队列队尾插入13;
d.push_back();
d.push_back();
for(int i=;i<d.size();i++)
{
cout<<"d["<<i<<"]="<<d[i]<<endl;
}
return ;
} //用迭代器访问deque元素
#include<deque>
#include<iostream>
using namespace std;
int main()
{
deque<string>d;
d.push_back("a");
d.push_back("b");
d.push_back("c");
deque<string>::iterator i,iend;
iend=d.end();//指向双端队列的下一个迭代器
int j;
for(i=d.begin(),j=;i!=iend;i++,j++)
//指向双向队列队首的迭代器
cout<<*i<<" ";
cout<<endl;
return ;
} #include<deque>
#include<iostream>
using namespace std;
int main()
{
deque<int>d;
d.push_back();
d.push_back();
d.push_front();//双端队列队首插入元素5
for(i=;i<d.size();i++)
cout<<d[i]<<" ";
cout<<endl;
d.insert(d.begin()+,);
for(int j=;j<d.size();j++)
cout<<d[j]<<" ";
cout<<endl;
return ;
} #include<deque>
#include<iostream>
using namespace std;
int main()
{
deque<int>d;
d.push_back();
d.push_back();
d.push_back();
d.push_back();
d.push_back();
d.push_back();
for(int i=;i<d.size();i++)
cout<<d[i]<<' ';
cout<<endl;
d.erase(d.begin()+);//指向双端队列队首的迭代器
d.pop_front();//删除双端队列对首元素
d.pop_back();//删除双端队列队尾元素
for(int j=;j<d.size();j++)
cout<<d[j]<<' ';
cout<<endl;
d.clear();//deque元素全部清除
return ;
}
//list
//assign()给list赋值
//begin()返回指向第一个元素的迭代器
//clear()删除所有元素
//empty()如果list是空的话则返回true
//end()返回末尾的迭代器(返回最后一个元素的下一个迭代器)
//erase()删除一个元素
//front()返回第一个元素
//insert()插入一个元素到list中
//max size()返回list能容纳的最大元素数量
//merge()合并两个list
//pop_back()删除最后一个元素
//pop_front()删除第一个元素
//push_back()在list的末尾添加一个元素
//push_front()在list的头部添加一个元素
//rbegin()返回指向第一个元素
//remove()从list删除元素
//remove if()按指定条件删除元素
//rend()指向list末尾的逆向迭代器
//resize()改变list的大小
//reverse()把list的元素倒转
//size()返回list中的元素个数 //用list处理整型数据
#include<iostream>
#include<list>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
list<int>listone;
list<int>::iterator i;
listone.push_front();//在list的头部添加一个元素
listone.push_front();
listone.push_back();//在list的末尾添加一个元素
listone.push_back();
for(i=listone.begin();i!=listone.end();++i)
//返回指向第一个元素的迭代器
cout<<*i<<" ";
cout<<endl;
} //用list处理字符型数据
#include<iostream>
#include<list>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
list<char>listtwo;
list<char>::iterator j;
listtwo.push_front('A');//在list的头部添加一个元素
listtwo.push_front('B');
listtwo.push_back('x');//在list的末尾添加一个元素
listtwo.push_back('y');
for(j=listtwo.begin();j!=listtwo.end();++j)
cout<<char(*j)<<" ";
cout<<endl;
}

STL学习的更多相关文章

  1. 标准模板库(STL)学习探究之stack

    标准模板库(STL)学习探究之stack queue priority_queue list map/multimap dequeue string

  2. 标准模板库(STL)学习探究之vector容器

    标准模板库(STL)学习探究之vector容器  C++ Vectors vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数据结构和算法的模板类和函数库.vector之所以被 ...

  3. ###STL学习--vector

    点击查看Evernote原文. #@author: gr #@date: 2014-08-11 #@email: forgerui@gmail.com vector的相关问题.<stl学习> ...

  4. ###STL学习--关联容器

    点击查看Evernote原文. #@author: gr #@date: 2014-08-23 #@email: forgerui@gmail.com STL中的关联容器. ###stl学习 |--迭 ...

  5. ###STL学习--迭代器

    点击查看Evernote原文. #@author: gr #@date: 2014-08-23 #@email: forgerui@gmail.com STL中的迭代器. ###stl学习 |--迭代 ...

  6. ###STL学习--函数对象

    点击查看Evernote原文. #@author: gr #@date: 2014-08-13 #@email: forgerui@gmail.com 在stl中,函数对象被大量地使用,用以提高代码的 ...

  7. ###STL学习--适配器

    点击查看Evernote原文. #@author: gr #@date: 2014-08-24 #@email: forgerui@gmail.com STL中的适配器. ###stl学习 |--迭代 ...

  8. STL学习:STL库vector、string、set、map用法

    本文仅介绍了如何使用它们常用的方法. vector 1.可随机访问,可在尾部插入元素:2.内存自动管理:3.头文件#include <vector> 1.创建vector对象 一维: (1 ...

  9. Effective STL 学习笔记 39 ~ 41

    Effective STL 学习笔记 39 ~ 41 */--> div.org-src-container { font-size: 85%; font-family: monospace; ...

  10. Effective STL 学习笔记 Item 38 : Design functor classes for pass-by-value

    Effective STL 学习笔记 Item 38 : Design functor classes for pass-by-value */--> div.org-src-container ...

随机推荐

  1. C#线程同步控制

    ManualResetEvent类,用于通知一个或多个正在等待的线程已发生事件,它有2种状态:有信号(true)的无信号(false). 有2种方法可以设置它的信号状态:构造函数构造的时候设置或者通过 ...

  2. js之字符串操作

    1.字符串查找 var str = "source_content10"; if(str.indexOf("source_content") !== false ...

  3. MSSQLSERVER服务无法启动的解决方案

    MSSQLSERVER服务无法启动的解决方案 有时候sqlserver无法启动了,原因是mssqlserver服务没有启动,当你手动启动时,又出现服务无法响应的可恶错误提示... 笔者“有幸”遇到了, ...

  4. iOS8以后自动计算cell的高度

    前提: 1.iOS系统>=8 2.cell中的每个控件布局固定,不含一些动态的模块,但是可以含有label的变化 可以采用tableView自动计算cell的高度 首先设置tableView的属 ...

  5. 如何理解反向传播 Backpropagation 梯度下降算法要点

    http://colah.github.io/posts/2015-08-Backprop/ http://www.zhihu.com/question/27239198 待翻译 http://blo ...

  6. MBProgressHud添加自定义动画

    在使用自定义view时,若直接使用,如下 MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; hud ...

  7. java多线程详解(4)-多线程同步技术与lock

    前言:本篇文章是对Synchronized和java.util.concurrent.locks.Lock的区别进行了详细的分析介绍 上一篇文章末最后介绍了synchronized的一些缺陷,本文主要 ...

  8. Android长时间后台运行Service

         项目需要在后台获取GPS经纬度.当用户对手机有一段时间没有操作后,屏幕(Screen)将从高亮(Bright)变为暗淡(Dim),如果再过段时间没操作, 屏幕(Screen)将又由暗淡(Di ...

  9. IIS发布WCF服务项目之本地

    最近由于项目需求,要做一个上传文件附件的功能,由于是多用户访问,所以这就用到了WCF服务,程序编写完成就需要发布了, 下面记录下发布到IIS的过程: 1,安装IIS 第一步:检查Windows7中II ...

  10. aa3

    var geoCoordMap = { "海门":[121.15,31.89], "鄂尔多斯":[109.781327,39.608266], "招远 ...