如何优雅的写C++代码(一)
时间:2014-02-27 07:39:06
收藏:0
阅读:580
// get the greatest power of two that is a divisor of n: return n&-n; // swap two integers a and b: a^=b^=a^=b; a^=b, b^=a, a^=b; // check whether a (nature number > 1) is a power of two or not: return ( ! ( x & (x-1))); return (x&-x) == x; // count number of bits set in v: for( int i=0; v; i++) v &= v - 1; // copy two char array while(*s++ = *t++); // binary search int left = 0, right = N; for( int mid=(left+right)>>1; right-left>1; mid = left + (right-left)>>1) (arr[mid] > x ? left : right ) = mid; return right;
原文:http://www.cnblogs.com/naive/p/3568886.html
评论(0)