stl总结精简版
STL 精简版
vetor
#include<vector>
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main()
{
vector <int> a;//定义一维数组
vector <int *> tm; //定义二位数组
int b = ;
a.push_back(b);//在数组的最后添加一个数据
a.push_back();
a.push_back();
a.pop_back();//去掉数组的最后一个数据
cout<<a.at()<<endl;//得到编号位置的数据
vector<int>::iterator it;
for(it = a.begin(); it != a.end(); it++){
printf("%d ",*it);
}
puts("");
printf("front = %d; back = %d\n",a.front(),a.back());
it = a.begin();
a.erase(it);//删除指针数据项
for(int i = ; i < a.size(); i++){
printf("%d ",a[i]);
}
puts("");
a.clear();//清空
if(a.empty()) puts("now its over");
return ;
}
set
#include<set>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct Node{
char str[];
bool operator < (const Node a) const {
return (strcmp(str,a.str) <= );
}
};
int main()
{
set<int>s;
s.insert();
s.insert();
s.insert();
//set中不会有重复的元素,所以我们如果需要去重,直接丢到set里是不错的选择
//set可以定义比较函数,因为set可以通过中序遍历直接从小到大的排序输出 //中序遍历
set<int>::iterator it;
for(it = s.begin(); it != s.end(); it++){
printf("%d ",*it);
}
puts("");
s.erase();//删除键值为2的元素
printf("find(3) = %d\n",s.find());
for(it = s.begin(); it != s.end(); it++){
printf("%d ",*it);
}
puts("");
s.clear();//清空set
if(s.empty()) puts("Now its over"); set<Node> n;
Node tm;
tm.str[] = 's'; tm.str[] = 'o';tm.str[] = ;
n.insert(tm);
Node tm2;
tm2.str[] = 'g'; tm2.str[] = 'e';tm2.str[] = ;
printf("%d\n", (tm < tm2));
printf("%d\n", (strcmp("ge", "so")));
tm.str[] = 'g'; tm.str[] = 'e';tm.str[] = ;
n.insert(tm);
tm.str[] = 's'; tm.str[] = 'i';tm.str[] = ;
n.insert(tm);
tm.str[] = 'b'; tm.str[] = 'e';tm.str[] = ;
n.insert(tm);
tm.str[] = 'd'; tm.str[] = 'n';tm.str[] = ;
n.insert(tm);
set<Node>::iterator p;
for(p = n.begin(); p!=n.end(); p++ ){
printf("%s ",(*p).str);
}
puts("");
return ;
}
stack
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stack>
using namespace std; int main()
{
stack<int> st;
st.push();
st.push();
st.push();
while(!st.empty()){
printf("%d ", st.top());
st.pop();
}
puts("");
printf("size = %d\n",st.size());
return ;
}
queue
#include<cstdio>
#include<queue>
using namespace std;
int main()
{
queue<int> qu;
for(int i = ; i < ; i++){
qu.push(i);
}
printf("front = %d; back = %d\n",qu.front(), qu.back());
while(!qu.empty()){
printf("%d ",qu.front());
qu.pop();
}
puts("");
printf("size = %d\n",qu.size());
return ;
}
priority_queue
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int main()
{
priority_queue<int> q;
for(int i = ;i < ; i++) q.push(i);
while(!q.empty()){
printf("%d ",q.top());
q.pop();
}
puts("");
return ;
}
stl总结精简版的更多相关文章
- Linux上oracle精简版客户端快速部署
RHEL6 + Oracle 11g客户端快速部署 需求:只是用到客户端的sqlplus, sqlldr功能. 方案:用精简版实现客户端的快速部署 1.上传oracle精简版客户端到服务器/tmp目录 ...
- ArcGIS10.2.1精简版、ArcGIS_Desktop10_Tutorial、破解文件等下载地址
原版ArcGIS for Desktop的ISO文件一般都在4.5G以上,一般人用不上里面很多工具,下载回来又浪费时间,现推出ArcGIS10.2.1精简版(里面只包含主程序.Data Interop ...
- TeamViewer12.0.71503(远程控制软件)精简版 单文件企业版介绍
TeamViewer 是一款能在任何防火墙和 NAT 代理的后台用于远程控制,桌面共享和文件传输的简单且快速的解决方案.为了连接到另一台计算机,只需要在两台计算机上同时运行 TeamViewer 即可 ...
- Log4j快速使用精简版
Log4j快速使用精简版 1.导入log4j-1.2.17.jar包 2.在src根目录下创建log4j.properties文件 log4j.rootLogger=INFO, CONSOLE, FI ...
- VMware10.06精简版安装后台运行
VMware10.06精简版安装时会出现一个安装功能选择菜单,里面有一条后台运行必选功能,一般人会跳过条.当你打算在服务器上用vmware时,一定要安装后台运行服务,否则你无法换出正在运行的后台虚拟机 ...
- [异常解决] ubuntu上安装虚拟机遇到的问题(vmware坑了,virtual-box简单安装,在virtual-box中安装精简版win7)
利用周末时间将整个电脑格式化,换成了ubuntu系统- 所谓:扫清屋子再请客! 但是有些软件只在win上有,于是还是考虑装个虚拟机来个——逐步过度策略,一点点地从win上转移到linux上 我的系统是 ...
- 电脑公司最新GHOST WIN7系统32,64位优化精简版下载
系统来自系统妈:http://www.xitongma.com 电脑公司最新GHOST win7系统32位优化精简版V2016年3月 系统概述 电脑公司ghost win7 x86(32位)万能装机版 ...
- TeamViewer12.0.71503(远程控制软件)精简版单文件企业版介绍
TeamViewer 是一款能在任何防火墙和 NAT 代理的后台用于远程控制,桌面共享和文件传输的简单且快速的解决方案.为了连接到另一台计算机,只需要在两台计算机上同时运行 TeamViewer 即可 ...
- centos7精简版(minimal)killall: command not found
centos7精简版(minimal)运行killall命令提示 command not found 是由于没有安装psmisc所致 Psmisc软件包包含三个帮助管理/proc目录的程序. 安装下列 ...
随机推荐
- android studio 环境变量配置
1.需要添加path环境变量: 2.真机调试或模拟器调试需要启动adb adb kill-severadb -start-server可能有端口冲突--重启或者修改端口 创建密匙http://blog ...
- APP上传APP Store遇到的各种问题
内容含敏感话题或对苹果不友好的信息(如苹果婊) 使用了友盟的统计SDK,获取了IDFA但是上传填写无广告 采用友盟IDFA的sdk,并用友盟的默认淘宝页面广告,被告知和产品内容不符(最近) App在i ...
- [WinForm]委托应用①——窗口之间方法/控件调用
不传参数 第二窗口:public partial class Form2 : Form { /// <summary> /// 定义委托 /// </summary> publ ...
- P神的SDFZ考试题 C题
探险[问题描述] 探险家小 T 好高兴! X 国要 ...
- C#序列化总结
贴一下自己序列化的代码: public class XMLUtil { /// <summary> /// XML & Datacontract Serialize & D ...
- CPP--关于long的争议和思考
先普及一下VS开发Linux的知识点 VS2017的安装:https://www.cnblogs.com/dunitian/p/8051985.html 创建项目在这 第一次运行的时候会让输入服务器信 ...
- 20行JS代码实现贪吃蛇
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- XML文件解析数据结构
最近在解析Android安装包内经过编译的二进制XML文件时想在内存中建立起其对应的树结构. 想了一早晨,思路如下图. 多叉树中的每个节点除了有子节点和兄弟节点以外还有一个指针指向父节点,然后根据状态 ...
- C#设计模式之二十三解释器模式(Interpreter Pattern)【行为型】
一.引言 今天我们开始讲"行为型"设计模式的第十一个模式,也是面向对象设计模式的最后一个模式,先要说明一下,其实这个模式不是最后一个模式(按Gof的排序来讲),为什么把它放在最 ...
- Tsung:开源多协议分布式负载&压力测试工具
Main features High Performance: the load can be distributed on a cluster of client machines Multi-pr ...