leetcode中常用函数和类型

来源:互联网 发布:eminem光明会 知乎 编辑:程序博客网 时间:2024/06/03 20:52

边做题边整理吧!好多不常用经常忘记

  1. 函数
Function for_each(InputIterator first, InputIterator last, Function f){    for ( ; first!=last; ++first ) f(*first);    return f;}

解释:迭代器所标记范围内的每个元素赋给f作为参数,并返回计算后的f, f不一定是函数。
例如:

unordered_map < int, int > count_map; // 记录每个元素的出现次数for_each( num.begin(),   //第一个参数          num.end(), //第二个参数          [&count_map](int e)//第三个参数          {         if (count_map.find(e) !=count_map.end())            count_map[e]++;         else            count_map[e] = 1;          }             );

指针函数,是一个函数,返回类型是指针。
int *f(x,y);
函数指针,是指针,指向函数。
int (*f)(x,y);

0 0
原创粉丝点击