fill(vs2010)

  • 引言
这是我学习总结<algorithm>的第十三篇,fill是一个很好的初始化工具。大学挺好,好好珍惜。。。
  • 作用
fill  的作用是 给容器里一个指定的范围初始为指定的数据。
In English, that is
Fill range with value
Assigns  val to all the elements in the range  [first,last).
  • 原型
template <class ForwardIterator, class T>
void fill (ForwardIterator first, ForwardIterator last, const T& val)
{
while (first != last) {
*first = val;
++first;
}
}

  • 实验
数据初始化为


std::fill (myvector.begin(),myvector.begin()+4,5);



std::fill (myvector.begin()+3,myvector.end()-2,8); 



  • 代码
test.cpp
#include <iostream>     // std::cout
#include <algorithm> // std::fill
#include <vector> // std::vector int main () {
std::vector<int> myvector (8); // myvector: 0 0 0 0 0 0 0 0 std::fill (myvector.begin(),myvector.begin()+4,5); // myvector: 5 5 5 5 0 0 0 0
std::fill (myvector.begin()+3,myvector.end()-2,8); // myvector: 5 5 5 8 8 8 0 0 std::cout << "myvector contains:";
for (std::vector<int>::iterator it=myvector.begin(); it!=myvector.end(); ++it)
std::cout << ' ' << *it;
std::cout << '\n';
system("pause");
return 0;
}

算法之旅,直奔<algorithm>之十三 fill的更多相关文章

  1. SHA1 安全哈希算法(Secure Hash Algorithm)

    安全哈希算法(Secure Hash Algorithm)主要适用于数字签名标准 (Digital Signature Standard DSS)里面定义的数字签名算法(Digital Signatu ...

  2. 【算法】狄克斯特拉算法(Dijkstra’s algorithm)

    狄克斯特拉算法(Dijkstra’s algorithm) 找出最快的路径使用算法——狄克斯特拉算法(Dijkstra’s algorithm). 使用狄克斯特拉算法 步骤 (1) 找出最便宜的节点, ...

  3. 一文读懂 深度强化学习算法 A3C (Actor-Critic Algorithm)

    一文读懂 深度强化学习算法 A3C (Actor-Critic Algorithm) 2017-12-25  16:29:19   对于 A3C 算法感觉自己总是一知半解,现将其梳理一下,记录在此,也 ...

  4. [转]EM算法(Expectation Maximization Algorithm)详解

    https://blog.csdn.net/zhihua_oba/article/details/73776553 EM算法(Expectation Maximization Algorithm)详解 ...

  5. Floyd判圈算法 Floyd Cycle Detection Algorithm

    2018-01-13 20:55:56 Floyd判圈算法(Floyd Cycle Detection Algorithm),又称龟兔赛跑算法(Tortoise and Hare Algorithm) ...

  6. 蓝桥杯——试题 算法训练 Yaroslav and Algorithm

    试题 算法训练 Yaroslav and Algorithm 资源限制 时间限制:100ms 内存限制:128.0MB 问题描述 (这道题的数据和SPJ已完工,尽情来虐吧!) Yaroslav喜欢算法 ...

  7. 素数算法(Prime Num Algorithm)

    素数算法(Prime Num Algorithm) 数学是科学的皇后,而素数可以说是数学的最为核心的概念之一.围绕素数产生了很多伟大的故事,最为著名莫过于哥德巴赫猜想.素数定理和黎曼猜想(有趣的是,自 ...

  8. 算法之旅,直奔<algorithm>之十四 fill_n

    fill_n(vs2010) 引言 这是我学习总结<algorithm>的第十四篇,作为fill的亲兄弟,fill_n也会助你一把的. 作用 fill_n 的作用是给一段指定长度的数据向量 ...

  9. 算法之旅,直奔<algorithm>之十七 find_first_of

    find_first_of(vs2010) 引言 这是我学习总结 <algorithm>的第十七篇,find_first_of是匹配的一个函数.<algorithm>是c++的 ...

随机推荐

  1. css清除浮动的几种方法整理

    四种清除浮动方法如下: 1.使用空标签清除浮动.空标签可以是div标签,也可以是P 标签.这种方式是在需要清除浮动的父级元素内部的所有浮动元素后添加这样一个标签 清除浮动,并为其定义CSS代码:cle ...

  2. Layer 1: Single Objects

    Layer 1: 单一对象 粗略的说, 在javascript中所有对象都是maps的键值对. 键值对的实体在对象中称为属性( property).属性的key经常为 string类型,而他的valu ...

  3. android Failure [INSTALL_FAILED_OLDER_SDK] 安装apk失败

    安装文件与运行环境的skd不匹配 打开源码目录下的AndroidManifest.xml文件,然后注释掉或者删除掉这行: <uses-sdk android:minSdkVersion=&quo ...

  4. html5 动画精灵

    <!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...

  5. ActionBar官方教程(3)更改标题处的图片

    Using a logo instead of an icon By default, the system uses your application icon in the action bar, ...

  6. 【原创翻译】Reducing Branch Delay to Zero in Pipelined Processors

    在流水线处理器中减少分支延迟到零 Antonio M. Gonzalez and Jose M. Llaberia 摘要 一种减少流水处理器中分支延迟到零的机制将在本文被描述以及评估.这种机制基于多重 ...

  7. WCF - Consuming WCF Service

    WCF services allow other applications to access or consume them. A WCF service can be consumed by ma ...

  8. java数据类型图:

    java数据类型图:                                 ┏数值型━┳━整数型:byte short int long               ┏基本数据类型━━┫   ...

  9. c#中Lock(锁)的研究以及跨线程UI的操作

    本文只针对C#中,多线程同步所用到的锁(lock)作为研究对象.由于想更直观的显示结果,所以,在做demo的时候,就把多线程通过事件操作UI的代码也写了出来,留作备忘和分享吧.       其实多线程 ...

  10. [HDU 1520] Anniversary party

    Anniversary party Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others ...