The Wayback Machine - https://web.archive.org/web/20180221032212/http://ja.cppreference.com:80/w/cpp/algorithm/reverse
名前空間
変種
操作

std::reverse

提供: cppreference.com
< cpp‎ | algorithm

 
 
アルゴリズムライブラリ
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を非改変
Original:
Non-modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
シーケンス動作を変更する
Original:
Modifying sequence operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
操作を仕切る
Original:
Partitioning operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)ソート操作
Original:
Sorting operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
バイナリ検索操作(ソート範囲で)
Original:
Binary search operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
(ソートされた範囲で)操作を設定します
Original:
Set operations (on sorted ranges)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ヒープ操作
Original:
Heap operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
最小値/最大値操作
Original:
Minimum/maximum operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
数値演算
Original:
Numeric operations
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Cライブラリ
Original:
C library
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
 
Defined in header <algorithm>
template<class BidirIt >
void reverse( BidirIt first, BidirIt last );
レンジ[first, last)の要素の順序を反転.
Original:
Reverses the order of the elements in the range [first, last).
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集]パラメータ

first, last -
逆転する要素の範囲
Original:
the range of elements to reverse
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
型の要件
-
BidirItBidirectionalIterator

の要求を満足しなければなりません。

-
The type of dereferenced BidirIt must meet the requirements of Swappable.

[編集]値を返します

(なし)

[編集]可能な実装

template<class BidirIt>void reverse(BidirIt first, BidirIt last){while((first != last)&&(first !=--last)){std::swap(*first++, *last);}}

[編集]

#include <vector>#include <iostream>#include <algorithm>   int main(int argc, char** argv){std::vector<int> v({1,2,3}); std::reverse(std::begin(v), std::end(v));std::cout<< v[0]<< v[1]<< v[2]<<'\n';   int a[]={4, 5, 6, 7}; std::reverse(&a[0], &a[4]);std::cout<< a[0]<< a[1]<< a[2]<< a[3]<<'\n';}

出力:

321 7654

[編集]複雑性

firstlastとの間の距離の線形
Original:
linear in the distance between first and last
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集]参照

逆転された範囲のコピーを作成します
Original:
creates a copy of a range that is reversed
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(関数テンプレート)[edit]
close