常用小函数——不要重复造轮子

abs()

#include <cmath>

In C++, this function is also overloaded in header <cmath> for floating-point types (see cmath abs), in header<complex> for complex numbers (see complex abs), and in header <valarray> for valarrays (see valarray abs).

在C++ 重载为各种类型,掉渣天的连复数也有。头文件 cmath

 

需要注意的是,cstdlib中也包含有abs,不过这个只支持int和longlong,并不支持浮点型,浮点型用另外一个fabs,同样包含在cstdlib

经实验,如果cmath和cstdlib同时包含的话,是可以用abs处理浮点数的。


 

max()  min() swap()

using namespace std;

支持各种类型包括自定义结构体,使用的是template机制。

根据www.cplusplus.com表示,在c++11之前版本,这些都包含在algorithm,不过在本机codeblocks v12.11上都是只需要std即可了。


 next_permutation()  prev_permutation();

#include <algorithm>

函数定义bool next_permutation (BidirectionalIterator first,BidirectionalIterator last);

           or  bool next_permutation (BidirectionalIterator first,BidirectionalIterator last, Compare comp);

First 是 头迭代器, last是尾迭代器,  作用是使得[first,last)内的数字按照比较算子comp(默认为小于号)来获得下一个序列.

prev_permutation同理

不定期更新

转载于:https://www.cnblogs.com/someblue/p/3597931.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值