c++ 容器元素填充(generate)
#include <iostream> // cout
#include <algorithm> // generate
#include <vector> // vector
#include <ctime> // time
#include <cstdlib> // rand, srand
using namespace std;
// function generator:
int RandomNumber () { return (rand()%); } // class generator:
struct c_unique {
int current;
c_unique() {current=;}
int operator()() {return ++current;}
} UniqueNumber; int main () {
srand ( unsigned ( time() ) ); vector<int> myvector (); generate (myvector.begin(), myvector.end(), RandomNumber);// 通过函数生成 cout << "myvector contains:";
for (vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
cout << ' ' << *it;
cout << '\n'; generate (myvector.begin(), myvector.end(), UniqueNumber);// 通过结构体生成 cout << "myvector contains:";
for (vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
cout << ' ' << *it;
cout << '\n'; return ;
}
c++ 容器元素填充(generate)的更多相关文章
- c++ 容器元素填充指定数量的元素(generate_n)
#include <iostream> // cout #include <algorithm> // generate_n using namespace std; ; in ...
- c++ 容器元素填充(fill)
#include <iostream> // cout #include <algorithm> // fill #include <vector> // vect ...
- C++进阶 STL(3) 第三天 函数对象适配器、常用遍历算法、常用排序算法、常用算数生成算法、常用集合算法、 distance_逆序遍历_修改容器元素
01昨天课程回顾 02函数对象适配器 函数适配器是用来让一个函数对象表现出另外一种类型的函数对象的特征.因为,许多情况下,我们所持有的函数对象或普通函数的参数个数或是返回值类型并不是我们想要的,这时候 ...
- c++ STL 常用容器元素类型相关限制 指针 引用
c++ 的 STL 中主要有 vector , list, map, set , multimap,multiset 这些容器完全支持使用内置类型和指针(指针注意内存泄露问题). 就是说乱用智能指针 ...
- 5. Bean Validation声明式验证四大级别:字段、属性、容器元素、类
1024,代码改变世界.本文已被 https://www.yourbatman.cn 收录,里面一并有Spring技术栈.MyBatis.JVM.中间件等小而美的专栏供以免费学习.关注公众号[BAT的 ...
- [19/03/27-星期三] 容器_Iterator(迭代器)之遍历容器元素(List/Set/Map)&Collections工具类
一.概念 迭代器为我们提供了统一的遍历容器的方式 /* *迭代器遍历 * */ package cn.sxt.collection; import java.security.KeyStore.Ent ...
- Java提高十五:容器元素比较Comparable&Comparator深入分析
我们经常用容器来存放元素,通常而言我们是不关系容器中的元素是否有序,但有些场景可能要求容器中的元素是有序的,这个时候用ArrayList LinkedList Hashtable HashMap ...
- C++ 容器元素的存储和获取
1.存储对象,存储的是对象的副本,并不是原对象.2.获取对象,获取的是对象的引用,为什么要这样设计?a.存储对象只发生一次,而获取对象往往会有多次,获取对象,如果每次都返回对象的副本,这个开销很大.b ...
- c++ 插入容器元素(insert)
#include <iostream> #include <vector> using namespace std; int main () { vector<int&g ...
随机推荐
- Andrew Ng-ML-第十八章-大规模机器学习
1.学习大数据集 图1.学习大数据集 当数据集量为m=1亿时,进行梯度下降将会花费较大时间. 可以使用小量数据集进行训练,然后得出学习曲线. 左图是高方差,右图是高偏差. 总之是要通过高效的学习算法来 ...
- end=‘’
print('----------------') a = ['aa','bb','cc','dd','ee'] for i in range(len(a)): print(i,a[i])#默认换行 ...
- [LeetCode] 675. Cut Off Trees for Golf Event_Hard tag: BFS
You are asked to cut off trees in a forest for a golf event. The forest is represented as a non-nega ...
- [LeetCode] 161. One Edit Distance_Medium
Given two strings s and t, determine if they are both one edit distance apart. Note: There are 3 pos ...
- Summary: gcd最大公约数、lcm最小公倍数算法
欧几里德算法 欧几里德算法又称辗转相除法,用于计算两个整数a,b的最大公约数.其计算原理依赖于下面的定理: 定理:gcd(a,b) = gcd(b,a mod b) 证明:a可以表示成a = kb + ...
- 174. Dungeon Game(动态规划)
The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. ...
- tomcat 的最大连接数设置
前提说明为了确保服务不会被过多的http长连接压垮,我们需要对tomcat设定个最大连接数,超过这个连接数的请求会拒绝,让其负载到其它机器.达到保护自己的同时起到连接数负载均衡的作用. 动手去做一开始 ...
- json-lib-2.4-jdk15.jar所需全部JAR包.rar java jsoup解析开彩网api接口json数据实例
json-lib-2.4-jdk15.jar所需全部JAR包.rar java jsoup解析开彩网api接口json数据实例 json-lib-2.4-jdk15.jar所需全部JAR包.rar ...
- svn导出文件夹到另外目录export
svn导出文件夹到另外目录export 2.选择目录,下面两个选项不用勾选 3.有存在的文件选择overwrite覆盖,勾选下面的同样操作
- C/C++之进制转换
二进制.八进制.十进制.十六进制之间转换 一. 十进制与二进制之间的转换 (1) 十进制转换为二进制,分为整数部分和小数部分 ① 整数部分 方法:除2取余法,即每次将整数部分除以2,余数为该位权 ...