码迷,mamicode.com
首页 >  
搜索关键字:stl next_permutation    ( 6534个结果
《Effective C++》item25:考虑写出一个不抛异常的swap函数
std::swap()是个很有用的函数,它可以用来交换两个变量的值,包括用户自定义的类型,只要类型支持copying操作,尤其是在STL中使用的很多,例如:int main(int argc, _TCHAR* argv[]) { int a[10] = {1,2,3,4,5,6,7,8,...
分类:编程语言   时间:2014-05-19 15:22:41    阅读次数:378
stl sort分析
最近写代码,无意中发现了一个坑,关于自定义比较函数的stl sort函数的坑,于是记录下来。先贴代码: 1 #include 2 #include 3 #include 4 5 struct finder 6 { 7 bool operator()(int first, in...
分类:其他好文   时间:2014-05-19 14:47:48    阅读次数:319
STL算法 — sort
能使用STL的sort系列算法的前提是容器的迭代器必须为随机迭代器。所以,vector和deque天然适用。STL的sort算法采用了一些策略,在不同情况下采用不同的排序算法,以达到各种算法优势互补的效果。基本的原则是:数据量大时采用快速排序,数据量小时采用插入排序(这是对快排常用的一种优化策略),递归层次过深改用堆排序。 首先是插入排序。它的平均和最坏时间复杂度都为O(N²),量级小于...
分类:其他好文   时间:2014-05-18 14:40:31    阅读次数:241
LeetCode: Next Permutation [030]
【题目】 Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order). The replac...
分类:其他好文   时间:2014-05-18 09:54:53    阅读次数:242
图基本算法 最小生成树 Prim算法(邻接表+优先队列STL)
图基本算法,最小生成树,Prim,优先队列+邻接表
分类:其他好文   时间:2014-05-18 00:26:46    阅读次数:558
Leetcode | Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl...
分类:其他好文   时间:2014-05-17 23:39:30    阅读次数:272
uva 10391 Compound Words (字符串-hash)
uva 10391 Compound Words (字符串-hash) 题目大意: 有一堆按照字典序排好的字符串,问你有多少字符串是由其它两个字符串组成。 解题思路: 如果用两个字符串拼接看拼接好的字符串是否在字典中,一定会超时。 我们可以逆向,由于字符串的长度不是很长,所以把一个字符串拆为两个字符串看这两个字符串是否都在字典中即可 解题代码一: 判断字符串是否在字典中,可以用STL set,也是轻松AC 解题代码二: 判断字符串是否在字典中,可以用hash,于是手写ha...
分类:其他好文   时间:2014-05-16 02:48:12    阅读次数:377
STL算法 — copy
为了效率,copy算法可谓无所不用其极,通过分析copy算法能够体会STL的精妙。 首先是三个对外接口: template // 泛化版本 inline OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result) { ...
分类:其他好文   时间:2014-05-15 05:50:02    阅读次数:315
遵照std::allocator实现自定制的内存分配器
下面是标准库STL中allocator的实现 template class allocator : public _Allocator_base { // generic allocator for objects of class _Ty public: typedef allocator other; typedef _Allocator_base _Mybase; t...
分类:其他好文   时间:2014-05-15 05:05:57    阅读次数:385
operator->
在学习Stl的过程中,经常看到->符号的重载,但一直不太明白。 今天做了一个小测试,来看看如果调用它。 以list的迭代器为例,在 pointer operator->() const { return &(operator*());}中加入 cout str_list; str_list.push...
分类:其他好文   时间:2014-05-14 10:32:52    阅读次数:221
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!