stl中copy()函数_std :: rotate_copy()函数以及C ++ STL中的示例

stl中copy()函数

C ++ STL std :: rotate_copy()函数 (C++ STL std::rotate_copy() function)

rotate_copy() function is a library function of algorithm header, it is used to rotate left the elements of a sequence within a given range and copy the rotating elements to another sequence, it accepts the range (start, end) of the input sequence, a middle point, and an iterator pointing to start element of result sequence. It rotates the elements in such a way that the element pointed by the middle iterator becomes the new first element.

rotation_copy()函数算法标头的库函数,用于在给定范围内向左旋转序列的元素,并将旋转的元素复制到另一个序列,它接受输入序列的范围(开始,结束),一个中间点,以及一个指向结果序列开始元素的迭代器。 它以使中间迭代器指向的元素成为新的第一个元素的方式旋转元素。

Note: To use rotate_copy() function – include <algorithm> header or you can simple use <bits/stdc++.h> header file.

注意:要使用rotate_copy()函数 –包括<algorithm>头文件,或者您可以简单地使用<bits / stdc ++。h>头文件。

Syntax of std::rotate_copy() function

std :: rotate_copy()函数的语法

    std::rotate_copy(
iterator start,  
iterator middle, 
iterator end, 
iterator start_result);

Parameter(s):

参数:

  • iterator start – an iterator pointing to the first element of the sequence.

    迭代器开始 –指向序列第一个元素的迭代器。

  • iterator middle – an iterator pointing to the middle or any other elements from where we want to start the rotation.

    中间迭代器 –指向中间或我们要开始旋转的位置的任何其他元素的迭代器。

  • iterator end – an iterator pointing to the last element of the sequence.

    迭代器末端 –指向序列的最后一个元素的迭代器。

  • iterator start_result – an iterator pointing to the first element in result sequence.

    iterator start_result –指向结果序列中第一个元素的迭代器。

Return value: void – it returns noting.

返回值: void –返回注释。

Example:

例:

    Input:
//an array (source)
int arr[] = { 10, 20, 30, 40, 50 };
//vector
vector<int> v(5);
//rotating and copy array elements to the vector
rotate_copy(arr + 0, arr + 2, arr + 5, v.begin());
Output:
vector elements: 30 40 50 10 20

C ++ STL程序演示了std :: rotate_copy()函数的使用 (C++ STL program to demonstrate use of std::rotate_copy() function)

In this program, we have an array and a vector; we are rotating its elements from 2nd index and copying into the vector.

在这个程序中,我们有一个数组和一个向量。 我们将其元素从第二索引旋转并复制到向量中。

//C++ STL program to demonstrate use of
//std::rotate_copy() function
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
//main code
int main()
{
//an array (source)
int arr[] = { 10, 20, 30, 40, 50 };
//vector
vector<int> v(5);
//printing array and vector elements
cout << "array elements..." << endl;
for (int x : arr)
cout << x << " ";
cout << endl;
cout << "vector elements begfore rotating..." << endl;
for (int x : v)
cout << x << " ";
cout << endl;
//rotating and copy array elements to the vector
rotate_copy(arr + 0, arr + 2, arr + 5, v.begin());
cout << "vector elements after rotating..." << endl;
for (int x : v)
cout << x << " ";
cout << endl;
return 0;
}

Output

输出量

array elements...
10 20 30 40 50
vector elements begfore rotating...
0 0 0 0 0
vector elements after rotating...
30 40 50 10 20

Reference: C++ std::rotate_copy()

参考: C ++ std :: rotate_copy()

翻译自: https://www.includehelp.com/stl/std-rotate_copy-function-with-example.aspx

stl中copy()函数

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/378967.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

计量经济学建模_浅谈统计学模型(兼计量经济学模型)

计量经济学模型是从统计学模型中衍生出来的&#xff0c;故将它们一并放在此处进行说明。实际上&#xff0c;很多人在很久之前就督促我写一篇统计学和计量经济学模型的文章&#xff0c;但我太懒惰&#xff0c;一直拖到现在&#xff0c;也是十分汗颜。先讲一些统计学上的基础故事…

linux文件存储、inode、硬链接、软链接

目录介绍inode的内容inode的大小inode号码目录文件硬链接软链接介绍 文件储存在硬盘上&#xff0c;硬盘的最小存储单位叫做"扇区"&#xff08;Sector&#xff09;。每个扇区储存512字节&#xff08;相当于0.5KB&#xff09;。操作系统读取硬盘的时候&#xff0c;不会…

OSPF路由器建立全毗邻关系的状态转换过程

1&#xff09;Down状态&#xff1a;路由器不与其他任何路由器交换任何OSPF消息&#xff1b;2&#xff09;Init状态&#xff1a;接收方路由器已经接收到对端路由器的hello包&#xff0c;但是没有从对端路由器的hello包中发现自己的router-id.。此时通信是单向的&#xff1b;3&am…

JavaScript打包与解包工具

JavaScript Packer&#xff1a; http://packer.skiyo.cn/ JavaScript UnPacker&#xff1a; http://packer.skiyo.cn/unpacker.html 转载于:https://www.cnblogs.com/springmvc-hibernate/archive/2010/09/17/2484233.html

工具栏的打印图标不见了_显示屏下方的工具栏里的小图标不见了怎么弄回来

优质回答 回答者&#xff1a;昂天大笑出门去一般右下角那些小图标都是与系统同步启动的一些功能&#xff0c;有的是没必要让它们同步启动的&#xff0c;启动的东西越多&#xff0c;系统反应就越慢。你说的工具栏里的小图标没了&#xff0c;可能是那些工具不能和系统同步启动了&…

使用sshfs挂载linux远程服务器目录到windows

目录下载winfsp 和 sshfs-win使用方式1、添加连接2、连接3、其他操作修改&#xff1a;删除&#xff1a;下载winfsp 和 sshfs-win 前往 github 对应项目的 release 中下载最新版本&#xff1a; sshfs-win&#xff1a;https://github.com/billziss-gh/sshfs-win/releases winfs…

法学学士学位的完整形式是什么?

LL.B&#xff1a;拉丁文的Legum Baccalaureus(俗称法学学士) (LL.B: Legum Baccalaureus in Latin (commonly known as Bachelor of Laws)) LL.B is an abbreviation of Legum Baccalaureus in Latin which is generally known as Bachelor of Laws. It is a bachelors degree …

Qt创建工程及导入资源图片

一、打开软件 二、 三、 四、 五、 六、 七、 导入其他文件资源&#xff0c;比如图片资源&#xff1a; 一、 二、 三、 四、 五、 六、导入图片 七、 八、 该图片导入项目里面了

linux date命令设置时间

linux date命令设置时间其实很简单 # date -s 20060925 # date -s 21:19:50 第一行设置日期&#xff0c;第二行设置时间。 转载于:https://www.cnblogs.com/takeaction/archive/2013/01/21/2869107.html

protect 继承_(转)public、protect、private继承方式 C++

C里面的结构体内的成员不受任何机制保护&#xff0c;直接能用&#xff0c;比如StructtypeA.x;StructtypeA.y;StructtypeA.fun();而c则不同&#xff0c;c的类像强化型的结构体public公有继承protected保护继承private私有继承我们知道类的private和protected成员,在类外是不可以…

原型模型| 软件工程

A prototype means a preliminary model of anything which gives us a rough idea about the basic functionalities that the real model would have. The prototyping model follows the same strategy. 原型意味着任何事物的初步模型&#xff0c;这使我们对真实模型具有的基…

librtmp分析(发送数据包处理)

RTMP详细分析&#xff08;三次握手&#xff09; RTMP详细分析(Message 消息&#xff0c;Chunk分块) librtmp分析&#xff08;接收数据包处理&#xff09; rtmp协议中的message的发送涉及有message 分chunk、base header长度的变化、message header长度的变化&#xff0c;只查看…

爱博图--微博图片批量下载小工具

2010/10/10 13:21 更新支持新浪博客相册。 例如&#xff1a; http://photo.blog.sina.com.cn/category/u/1245856511/s/275046新浪的微博用户在发微博的时候&#xff0c;一般都会附加一张与相关的图片。例如&#xff1a;欧美街拍xoxo这位博主就是单纯的发图片。因此可以说新浪微…

FusionCharts图表标题的参数设置

FusionCharts 允许你为chart配置标题、子标题、x轴标题和y轴标题&#xff0c;可以为它们指定字体、样式和动画效果等。那么Chart的主标题、子标题、X轴标题和Y轴标题的参数应该怎样设置呢&#xff1f; Chart主标题 Chart的caption属性设置主标题。代码如下&#xff1a; <cha…

tomcat没有错,但是还是一闪而过(端口被占用)

首先&#xff0c;看tomcat日志文件&#xff0c;在tomcat目录下有个logs文件夹&#xff0c;进去找到刚才运行时的日志文件。 然后&#xff0c;我的是Address already in use: JVM_Bind <null>:8080&#xff0c;8080端口被占用了。 此时需要将该端口给kill掉 cmd netsta…

stl向量_用户定义大小的C ++ STL中的2D向量

stl向量C STL中的2D矢量 (2D Vector in C STL) In C STL, a 2D vector is a vector of vector. 在C STL中&#xff0c;二维向量是向量的向量。 Syntax to declare a 2D vector: 声明2D向量的语法&#xff1a; vector<vector<T>> vector_name{ {elements}, {ele…

librtmp分析(接收数据包处理)

RTMP详细分析&#xff08;三次握手&#xff09; RTMP详细分析(Message 消息&#xff0c;Chunk分块) librtmp分析&#xff08;发送数据包处理&#xff09; rtmp协议中的message的接收涉及有message 组合多个chunk、相对时间戳计算绝对值。 分析一下librtmp库中的int RTMP_ReadP…

动态可缓存的内容管理系统(CMS)(转)

摘要&#xff1a;内容管理系统(CMS)在各大商业站点和门户站点中扮演着重要的角色&#xff0c;是内容有效组织和快速发布极为重要的基础平台。目前主流的内容发布系统都使用静态页面进行内容发布&#xff0c;在我们的实际使用过程中我们深切的感受到静态内容发布存在着很多弊端&…

反转字符串中的元音字符_C程序消除字符串中的所有元音

反转字符串中的元音字符Given a string and we have to eliminate/ remove all vowels from the string using C program. 给定一个字符串&#xff0c;我们必须使用C程序从字符串中消除/删除所有元音。 To eliminate/remove the vowels 消除/删除元音 We will traverse (reac…

mysql 自动化 安装_mysql自动化安装

MySQL安装一般使用RPM或者源码安装的方式。RPM安装的优点是快速,方便.缺点是不能自定义安装目录.如果需要调整数据文件和日志文件的存放位置,还需要进行一些手动调整。源码安装的优点是可以自定义安装目录,缺点是编译时间长,过程复杂其实还有一种方式,定制RPM包.它相当于用源码…