stl中copy()函数_std :: rotate_copy()函数以及C ++ STL中的示例
stl中copy()函數(shù)
C ++ STL std :: rotate_copy()函數(shù) (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()函數(shù)是算法標(biāo)頭的庫(kù)函數(shù),用于在給定范圍內(nèi)向左旋轉(zhuǎn)序列的元素,并將旋轉(zhuǎn)的元素復(fù)制到另一個(gè)序列,它接受輸入序列的范圍(開(kāi)始,結(jié)束),一個(gè)中間點(diǎn),以及一個(gè)指向結(jié)果序列開(kāi)始元素的迭代器。 它以使中間迭代器指向的元素成為新的第一個(gè)元素的方式旋轉(zhuǎn)元素。
Note: To use rotate_copy() function – include <algorithm> header or you can simple use <bits/stdc++.h> header file.
注意:要使用rotate_copy()函數(shù) –包括<algorithm>頭文件,或者您可以簡(jiǎn)單地使用<bits / stdc ++。h>頭文件。
Syntax of std::rotate_copy() function
std :: rotate_copy()函數(shù)的語(yǔ)法
std::rotate_copy(iterator start, iterator middle, iterator end, iterator start_result);Parameter(s):
參數(shù):
iterator start – an iterator pointing to the first element of the sequence.
迭代器開(kāi)始 –指向序列第一個(gè)元素的迭代器。
iterator middle – an iterator pointing to the middle or any other elements from where we want to start the rotation.
中間迭代器 –指向中間或我們要開(kāi)始旋轉(zhuǎn)的位置的任何其他元素的迭代器。
iterator end – an iterator pointing to the last element of the sequence.
迭代器末端 –指向序列的最后一個(gè)元素的迭代器。
iterator start_result – an iterator pointing to the first element in result sequence.
iterator start_result –指向結(jié)果序列中第一個(gè)元素的迭代器。
Return value: void – it returns noting.
返回值: void –返回注釋。
Example:
例:
Input://an array (source)int arr[] = { 10, 20, 30, 40, 50 };//vectorvector<int> v(5);//rotating and copy array elements to the vectorrotate_copy(arr + 0, arr + 2, arr + 5, v.begin());Output:vector elements: 30 40 50 10 20C ++ STL程序演示了std :: rotate_copy()函數(shù)的使用 (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.
在這個(gè)程序中,我們有一個(gè)數(shù)組和一個(gè)向量。 我們將其元素從第二索引旋轉(zhuǎn)并復(fù)制到向量中。
//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 };//vectorvector<int> v(5);//printing array and vector elementscout << "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 vectorrotate_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 20Reference: C++ std::rotate_copy()
參考: C ++ std :: rotate_copy()
翻譯自: https://www.includehelp.com/stl/std-rotate_copy-function-with-example.aspx
stl中copy()函數(shù)
總結(jié)
以上是生活随笔為你收集整理的stl中copy()函数_std :: rotate_copy()函数以及C ++ STL中的示例的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 现在一黄金多少钱一克啊?
- 下一篇: 法学学士学位的完整形式是什么?