std::reverse

From Cppreference

Jump to: navigation, search
Defined in header <algorithm>

template< class BidirectionalIterator >
void reverse( BidirectionalIterator first, BidirectionalIterator last );

Reverses the order of the elements in the range [first, last).

Contents

Parameters

first, last - the range of elements to reverse

Return value

(none)

Equivalent function

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

Example

Complexity

linear in the distance between first and last

See also

reverse_copy
creates a copy of a range that is reversed
(function template)
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox
In other languages