博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c++stl和std_std :: rotate()函数以及C ++ STL中的示例
阅读量:2531 次
发布时间:2019-05-11

本文共 2342 字,大约阅读时间需要 7 分钟。

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
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 
#include
#include
using namespace std;//main codeint main(){
//vector vector
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 50vector elements after rotating...30 40 50 10 20

Reference:

参考:

翻译自:

c++stl和std

转载地址:http://vxtzd.baihongyu.com/

你可能感兴趣的文章
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_20、SpringBoot2.x配置全局异常实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第5节 SpringBoot部署war项目到tomcat9和启动原理讲解_23、SpringBoot2.x启动原理概述...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第4节 Springboot2.0单元测试进阶实战和自定义异常处理_21、SpringBoot2.x配置全局异常返回自定义页面...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_32..SpringBoot2.x持久化数据方式介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_34、SpringBoot整合Mybatis实操和打印SQL语句...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_35、事务介绍和常见的隔离级别,传播行为...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_40、Redis工具类封装讲解和实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_37、分布式缓存Redis介绍...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_42、SpringBoot常用定时任务配置实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第9节 SpringBoot2.x整合Redis实战_39、SpringBoot2.x整合redis实战讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第14节 高级篇幅之SpringBoot多环境配置_59、SpringBoot多环境配置介绍和项目实战...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_41、SpringBoot定时任务schedule讲解...
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_43、SpringBoot2.x异步任务实战(核心知识)...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_1_01课程简介
查看>>
小D课堂 - 零基础入门SpringBoot2.X到实战_第11节 Logback日志框架介绍和SpringBoot整合实战_45、SpringBoot2.x日志讲解和Logback配置实战...
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_1_02技术选型
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_汇总
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_01传统架构演进到分布式架构
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_02 微服务核心基础讲解
查看>>
小D课堂 - 新版本微服务springcloud+Docker教程_2_04微服务下电商项目基础模块设计...
查看>>