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()函数

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

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

    stl中copy()函数 C ++ STL std :: copy_if()函数 (C++ STL std::copy_if() function) copy_if() function is a l ...

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

    stl中copy()函数 C ++ STL std :: copy()函数 (C++ STL std::copy() function) copy() function is a library fu ...

  3. stl min函数_std :: min()函数以及C ++ STL中的示例

    stl min函数 C ++ STL std :: min()函数 (C++ STL std::min() function) min() function is a library function ...

  4. stl max函数_std :: max_element()函数以及C ++ STL中的示例

    stl max函数 C ++ STL std :: max_element()函数 (C++ STL std::max_element() function) max_element() functi ...

  5. c++stl和std_std :: replace()函数以及C ++ STL中的示例

    c++stl和std C ++ STL std :: replace()函数 (C++ STL std::replace() function) replace() function is a lib ...

  6. c++中STL的常用算法--1(函数对象,谓词,内建函数对象)

    函数对象 重载函数调用操作符的类,其对象常称为函数对象(function object),即它们是行为类似函数的对象,也叫仿函数(functor),其实就是重载"()"操作符,使得 ...

  7. c++stl和std_std :: rotate()函数以及C ++ STL中的示例

    c++stl和std C ++ STL std :: rotate()函数 (C++ STL std::rotate() function) rotate() function is a librar ...

  8. matlab中copy函数,Matlab 的函数

    &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp 预备知识 Matlab 的判断与循环 函数文件 我们已经学了 ...

  9. Dictionary作为数据源绑定,调用c++库中返回为BYTE*的函数,listView项排序

    最近在做一个电子档案管理的项目.现在还处于初期,只是做一个简单demo拿去跟客户演示.至于最后谈不谈得下来,到底做不做,反正我是不看好,但没因为这样就马马虎虎.草草了事.这个项目算是b/s加c/s混合 ...

最新文章

  1. SQL on Linux Run on Docker
  2. python之文件读写和异常处理
  3. python要学多久-python需要学多久?自学两年也很难达到企业标准!
  4. 69道Spring面试题和答案
  5. 办公自动化系统开发实例导航 源码_本色世界源码搭建(系统开发)
  6. csgo被会话踢出什么鬼_【解决方案】“CSGO游戏—断开连接,VAC无法验证会话”问题解决方案...
  7. LeetCode 2091. 从数组中移除最大值和最小值(一次遍历)
  8. python中的数字类型格式与运算,python数字数据类型
  9. 怎么把外部参照合并到图纸_CAD图纸中插入的参照底图如何使用
  10. 黑盒法测试c语言,黑盒测试的测试用例设计方法(经典理论知识,推荐)
  11. 微服务之间的调用方式RestTemplate和FeignClient
  12. mac下安装node.js步骤
  13. 生产环境mysql主主同步主键冲突处理
  14. svchost.exe进程内存占用过高案例解决方案一例
  15. [XCTF-Reverse] 13-18
  16. win7计算机资源管理器卡住,如何解决win7系统资源管理器已停止工作的问题
  17. android:TableRow之平均分布列
  18. Docker,compose,kitematic Overview and build Php WordExpress
  19. 重写 toFixed 方法,解决 四舍六入五成双 的问题
  20. 控制建模matlab练习02:状态空间方程系统

热门文章

  1. rostcm6情感分析案例分析_电商评论情感分析
  2. python购物车实现的功能是什么_Python3实现购物车功能
  3. JS里面的懒加载(lazyload)
  4. java读取文件方法
  5. timeval的时间转换成毫秒之后多大的数据类型可以装下
  6. 左侧固定,右侧自适应的布局方式(新增评论区大佬教的方法)
  7. 判断字符串是否为正整数 浮点小数
  8. 以A表中的值快速更新B表中记录的方法
  9. js中 javascript:void(0) 用法详解
  10. some fragments