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.pswp.cn/news/378967.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378967.shtml
英文地址,請注明出處:http://en.pswp.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包.它相當于用源碼…