日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

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

發布時間:2025/3/11 c/c++ 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 elementrotate(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() {//vectorvector<int> v{ 10, 20, 30, 40, 50 };//printing vector elementscout << "vector elements begfore rotating..." << endl;for (int x : v)cout << x << " ";cout << endl;//rotating vector from 2nd elementrotate(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中的示例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。