c++stl和std_std :: rotate()函数以及C ++ STL中的示例
c++stl和std
C ++ STL std :: rotate()函数 (C++ STL std::rotate() function)
rotate() function is a library function of algorithm header, it is used to rotate left the elements of a sequence within a given range, it accepts the range (start, end) and a middle point, it rotates the elements in such way that the element pointed by the middle iterator becomes the new first element.
rotation()函数是算法标头的库函数,用于在给定范围内向左旋转序列的元素,接受范围(开始,结束)和中间点,以这种方式旋转元素中间迭代器指向的元素将成为新的第一个元素。
Note: To use rotate() function – include <algorithm> header or you can simple use <bits/stdc++.h> header file.
注意:要使用rotate()函数 –包括<algorithm>头文件,或者您可以简单地使用<bits / stdc ++。h>头文件。
Syntax of std::rotate() function
std :: rotate()函数的语法
std::rotate(iterator start, iterator middle, iterator end);
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.
迭代器末端 –指向序列的最后一个元素的迭代器。
Return value: void – it returns noting.
返回值: void –返回注释。
Example:
例:
Input:
vector<int> v{ 10, 20, 30, 40, 50 };
//rotating vector from 2nd element
rotate(v.begin(), v.begin() + 2, v.end());
Output:
30 40 50 10 20
C ++ STL程序演示了std :: rotate()函数的使用 (C++ STL program to demonstrate use of std::rotate() function)
In this program, we have a vector and we are rotating its elements from 2nd index.
在此程序中,我们有一个向量,并从第二个索引开始旋转其元素。
//C++ STL program to demonstrate use of
//std::rotate() function
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
//main code
int main()
{//vector
vector<int> v{ 10, 20, 30, 40, 50 };
//printing vector elements
cout << "vector elements begfore rotating..." << endl;
for (int x : v)
cout << x << " ";
cout << endl;
//rotating vector from 2nd element
rotate(v.begin(), v.begin() + 2, v.end());
cout << "vector elements after rotating..." << endl;
for (int x : v)
cout << x << " ";
cout << endl;
return 0;
}
Output
输出量
vector elements begfore rotating...
10 20 30 40 50
vector elements after rotating...
30 40 50 10 20
Reference: C++ std::rotate()
参考: C ++ std :: rotate()
翻译自: https://www.includehelp.com/stl/std-rotate-function-with-example.aspx
c++stl和std
c++stl和std_std :: rotate()函数以及C ++ STL中的示例相关推荐
- c语言 函数的参数传递示例_restder()函数,带有C ++中的示例
c语言 函数的参数传递示例 C ++ restder()函数 (C++ remainder() function) remainder() function is a library function ...
- c语言atoll函数怎么用_C ++中带有示例的atoll()函数
c语言atoll函数怎么用 C ++ Atoll()函数 (C++ atoll() function) atoll() function is a library function of cstdli ...
- c++ hashset的用法_c++ stl容器set成员函数介绍及set集合插入,遍历等用法举例
c++ stl集合set介绍 c++ stl集合(Set)是一种包含已排序对象的关联容器.set/multiset会根据待定的排序准则,自动将元素排序.两者不同在于前者不允许元素重复,而后者允许. 1 ...
- c语言中set 函数,C里边的STL里边的Set函数
set函数的用法: 这是一个集合函数,这个函数可以处理很多的元素,这些元素可以去重,把相同的元素都去掉,剩下不一样的元素,而且还可以自动给这些元素来排序,从小到大的顺序来排序. 这里我们先来举个例子: ...
- STL的rotate函数分析
STL的rotate其实就可以看做是一个循环移位的函数. 首先对于循环移位操作有以下的几种思路: 1)最简单的想法就是每次移动一位进行循环遍历整个容器,算法复杂度为O(n*m). 2)运用分组交换(尽 ...
- C++中的rotate函数
写在前面 在C++中rotate函数有多中重载类型,这里只讨论一种情况,当STL中对应容器的迭代器类型为ForwardIteartor以及更低的情况,我们不开辟新的空间,直接在容器上完成旋转,不借助任 ...
- OpenCV代码提取:rotate函数的实现
OpenCV中并没有直接提供实现rotate的函数,这里通过getRotationMatrix2D和warpAffine函数实现rotate,并增加了一个crop参数,用来判断是否进行crop.目前支 ...
- html rotate()函数,CSS rotate()用法及代码示例
rotate()函数是一个内置函数,用于基于给定角度作为参数旋转元素.可以按照度数,刻度,弧度或转角设置角度. 用法: rotate( angle ) 参数:该功能接受代表旋转角度的单个参数角度.正角 ...
- 18函数对象19command模式20函数对象在STL中的应用
Item 18. Function Objects Item 19. Commands and Hollywood Item 20. STL Function Objects 1.unction Ob ...
最新文章
- 计算机维护系统Win8PE,u启动windows8PE工具箱
- 戴尔sc系列存储阵列柜服务器,国产化的戴尔存储 到底都长什么样?
- 程序编译是出现“field has incomplete type“问题的解决
- 像“打游戏”一样用Numpy,可视化编程环境Math Inspector了解一下? | 代码开源
- 【十五分钟Talkshow】谈谈HTML 5及其对Web开发人员的挑战和机遇
- sort ascend matlab,MATLAB sort函数用法
- django3安装rest_framework,并测试
- 经典排序算法(二十)--Strand Sort
- 管理感悟:软件第一法则
- Atitit Cookie安全法 目录 1. cookie分为 会话cookie 和 持久cookie ,	1 1.1. 安全措施	1 1.2. 3. cookie的同源策略	2 1.3. 安全类库
- Mnist数据集介绍
- java 回收器有几种_Java垃圾回收器种类
- 实现微信 委托代扣/包月服务
- 闹钟android 代码,android 闹钟app源码(Alarm)
- 用生产者消费者模式爬取斗图吧,一次性收获超多表情包【python爬虫入门进阶】(11)
- DNS服务(域名系统、过程、bind、配置文件、查看本设备dns)
- js实现购物车结算界面
- 微信小程序自动化构建(云效)
- VUE项目SEO问题的解决
- WebLogic的下载与安装
热门文章
- oracle如何设置权限,ORACLE的权限设置
- 深度学习编译:MLIR初步
- python可以做计量分析吗_技术分享 - python数据分析(2)——数据特征分析(上)...
- word计算机课教学反思,《WORD》初中信息技术的教学反思
- android aar jar制作,AndroidStudio aar、jar生成及其引用
- MySQL:进阶应用
- 九个案例简述Web设计原则:简洁清晰
- Problem E: 高于均分的学生
- Android 常用的数据加密方式
- Laravel核心代码学习--用户认证系统的实现细节