![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
c/c++知识点
扫地の小沙弥
算法和数据结构就是编程的一个重要部分,你若失掉了算法和数据结构,就似你失去了灵魂
展开
-
c++中的那些foreach循环
1. c++中的 for_each 函数for_each()事实上是個 function template,其源码如下link:http://www.cplusplus.com/reference/algorithm/for_each/?kw=for_eachtemplate<typename InputIterator, typename Function>Function ...原创 2019-02-21 13:29:17 · 68687 阅读 · 4 评论 -
幂函数的位运算解法
以我们常用的2的幂、3的幂、4的幂解法作为例子1. 2的幂解法问题: 判断一个数是否是2的幂解法一: 常规解法bool isPowerOfTwo(int n) { if (n <= 0) return false; int ans = 0; while (n != 0) { if (n&1) ans++; n >>= 1; }...原创 2019-02-22 13:57:07 · 1406 阅读 · 0 评论