STL+位运算
来源:互联网 发布:净利润算法 编辑:程序博客网 时间:2024/06/11 03:09
1.queue队列
头文件#include <queue>
queue<int>q;
queue<double>q;
queue<node>q;
入队列:q.push(x)将x元素放入队列的末端
出队列:q.pop()将第一个元素删除
访问队首元素:q.front
访问队中的元素的个数: q.size();
2.priority_queue优先队列priority模板类有三个参数,第一个是元素类型,第二个是容器类型,第三个是比较算子
priority_queue<int>q;
priority_queue<int,vector<int>,greater<int>>q;从小到大排列
priority_queue<int,vector<int>,less<int>>q;从大到小排列
访问优先队列的队首元素 q.top() ;
出队列: q.pop();
入队列: q.push(x);
判断优先队列是否为空: q.empty();
3.stack栈
stack的头文件 <stack>.
stack<int> s1;
stack<string> s2;
Stack 操作:
入栈 :q.push(x);
出栈 :q.pop(); 注意,出栈操作只是删除栈顶元素,并不返回该元素。
访问栈顶 :q.top();
判断栈空 :q.empty(); 当栈空的时, 返回true。
访问栈中的元素个数 :q.size();
Stack 操作:
入栈 :q.push(x);
出栈 :q.pop(); 注意,出栈操作只是删除栈顶元素,并不返回该元素。
访问栈顶 :q.top();
判断栈空 :q.empty(); 当栈空的时, 返回true。
访问栈中的元素个数 :q.size();
7.map
map是键-值对的集合。map类型通常可理解为关联数组。
map的头文件 :#include<map>;
map对象的定义:
map<string,int>q; map<int,int>q; map<string,node>q; map<int,node>; map<int,string>q;
map添加元素:
如:map<int,string>q; q[100]=”adnsnd”;
还可以:q.insert(pair<int,string>(100,”adnsnd”));
q.insert(map<int,string>::value_type(100,”adnsnd”)) ;
map查找并读取元素:
如map<int,string>q;
最简单的方法:int n=q[“dadad”];
7.set
头文件:#include<set>
set对象的定义:set<int>ivec;
set中添加元素:
ivec.insert(10);
set中获取元素
ivec.find(x);
判断x是否在ivec中出现过可以用:
ivec.find(x); 也可以用 ivec.count(x);这里count的返回值只能是1或0。
set的遍历;
set<int>::iterator it=ivec.begin();
While(it!=q.end())
{
printf(“%d ”,*it);
it++;}
set的删除元素:
it=ivec.find(x);
ivec.erase(it);
set 的lower_bound/upper_bound的用法:
使用迭代器 set<int>::iterator itlow,itup;
itlow=ivec.lower_bound(x);
itup=ivec.upper_bound(x);
lower_bound返回的是在ivec中大于或等于x的第一个数的位置,upper_bound返回的是在ivec中大于x的第一个数的位置;
- STL+位运算
- NYOJ 528 位运算 STL
- POJ3748 位操作【位运算+STL】
- NUC1419 位操作【位运算+STL】
- Same binary weight(stl 位运算)
- C++/STL Bitset 位运算类
- 位运算
- 位运算
- 位运算
- 位运算
- 位运算
- 位运算
- 位运算
- 位运算
- 位运算
- 位运算
- 位运算
- 位运算
- Elasticsearch模块功能之-快照和恢复(snapshot and restore)
- HDOJ 题目1284 钱币兑换问题(母函数,打表)
- java日期格式化
- 虚函数和纯虚函数的区别
- UIDatePicker
- STL+位运算
- HDU 1506 Largest Rectangle in a Histogram(DP)
- hdu 4908 BestCoder Sequence
- JAVA JNDI简介
- 从电容的名称认识电容的作用
- 【Linux入门学习之】Linux文件权限与目录配置(已修改过)
- HDU 2955
- hdu TIANKENG’s restaurant
- POJ 2394 Checking an Alibi (最短路+Dijkstra)