----2.4.1.STL
文章平均质量分 57
leoIsCoding
Github : [ https://github.com/leoChaoGlut ]
Email : [ [email protected] ]
展开
-
疑问:关于swap和next_permutation
奇怪了,做全排列的时候,在交换两个数时用到algorithm中的swap函数,效率竟然比自己写一个swap的效率差,是因为大量进行调用的原因吗?求解.... full_permutation 为我写的计算全排列数量的函数,没有使用algorithm中的swap函数, nextPerm 使用了algorithm中的next_permutation函数, full_permutation_原创 2015-01-23 11:18:14 · 1742 阅读 · 0 评论 -
STL sort升序排序小发现
今天做了个小测试,发现sort函数第三个参数不应该添加,添加之后反而效率更低了. 比如说,一般情况下,要将N个数升序排列,sort(arr,arr+arr.length(),cmp) 这个cmp函数是这样的: bool cmp(int a,int b) { return a>b; } 这样就可以使序列升序,但是效率没有sort(arr,arr+arr.length());reverse原创 2015-01-17 10:29:56 · 1836 阅读 · 0 评论 -
The efficiency of swap
swap1:Each pair of expressions are separated by comma. swap2:Each pair of expressions are divided by semicolon. swap3:inline function.swap #include #include #define swap1(a,b) a^=b,b^=a,a^=b #defin原创 2015-02-05 22:29:41 · 1329 阅读 · 0 评论