1. 顺序容器的初始化操作1.1 顺序容器(vector,list,deque)的五种初始化方法,以 vector 为例。#include #include #include using namespace std;int main(int argc, const char *argv[]){ .....
分类:
编程语言 时间:
2014-07-19 19:27:08
阅读次数:
278
唯一对外接口
/*--------------------------------------------------------------------------------------
* copy 函数及其重载形式
*/
//完全泛化版本。
template // ? 这里的 InputIterator 和 OutputIterator 都只是名称而已,哪里确保了它们真的至少是 InputIterator 和 O...
分类:
其他好文 时间:
2014-07-18 22:39:22
阅读次数:
302
描述、源码、示例
version 1:普通操作版本
version 2: 泛化操作版本
1.accumulate
描述:计算 init 和 [first, last) 内所有元素的总和
源码:
//version 1
template
T accumulate(InputIterator first, InputIterator last, T init) {
for ( ; first != last; ++first)
ini...
分类:
其他好文 时间:
2014-07-18 22:16:32
阅读次数:
283
1.iter_swap
描述:将两个 ForwardIterator 所指的对象对调
源码:
//version 1
template
inline void __iter_swap(ForwardIterator1 a, ForwardIterator2 b, T*) {
T tmp = *a;
*a = *b;
*b = tmp;
}
//version 2
template...
分类:
其他好文 时间:
2014-07-18 21:32:42
阅读次数:
244
转自:http://blog.csdn.net/holybin/article/details/26050897 0 概述 虽然hash_map和map都是STL的一部分,但是目前的C++标准(C++11)中只有map而没有hash_map,可以说STL只是部分包含于目前的C++标准中。主流的GNU...
分类:
其他好文 时间:
2014-07-18 19:20:07
阅读次数:
316
【程序员编程艺术】学习记录2:左旋转字符串之循环移位法
GCD算法:(辗转相除法/欧几里得算法)
gcd是求最大公约数的算法,作为TAOCP第一个算法
gcd算法流程:
首先给定两个整数m,n(m大于等于n)如果小于则直接交换再处理
①求余数 r=m%n
②假如r=0,算法结束,n即为所求
否则,重新令m
STL中rotate算法:
对于数组移位问题,可以采用下面方法:...
分类:
其他好文 时间:
2014-07-18 16:38:35
阅读次数:
243
1.Map1.1 map是一种pair的容器,pair的种类是pair。map采用下标访问一个已存在的key, 会更新value,访问map中不存在的元素时,会增加一个新的键值对。map中的元素按照key进行从小到大排列。map的底层实现是采用二叉树,一般是使用红黑树。#include #inclu...
分类:
编程语言 时间:
2014-07-18 14:30:07
阅读次数:
350
1、C++由四个次语言组成:c、c++类对象、template C++、STLc++高效编程守则视状况而变化,取决于使用c++的哪一部分。2、尽量以const、enum、inline替换#define a、常量定义式通常被放在头文件中(以便被不同的源码包含进去),如果想将常量指针(即指向常量的指针)...
分类:
编程语言 时间:
2014-07-17 22:35:59
阅读次数:
317
题解:数据结构的基本操作,用STL可以完美实现,就是比较慢……#include #include #include #include #include const int MAXN=500005; const int INF=~0U>>1; using namespace std; ...
分类:
其他好文 时间:
2014-07-17 17:39:20
阅读次数:
193
题解:直接使用STL中的hash去重即可#include #include using namespace std;int ans[50010];int main(){ int T,n,tmp; scanf("%d",&T); while(T--){ int cnt=...
分类:
其他好文 时间:
2014-07-17 10:02:58
阅读次数:
231