Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

reverse


Algorithm

Summary

Reverses the order of elements in a collection.

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

None

Synopsis

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

Description

The algorithm reverse reverses the elements in a sequence so that the last element becomes the new first element, and the first element becomes the new last. For each non-negative integer i <= (last - first)/2, reverse applies swap to all pairs of iterators first + I, (last - I) - 1.

Because the iterators are assumed to be bidirectional, reverse does not return anything.

Complexity

reverse performs exactly (last - first)/2 swaps.

Example

Program Output

Warnings

If your compiler does not support default template parameters, then you always need to supply the Allocator template argument. For instance, you need to write:

vector<int, allocator<int> >

instead of:

vector<int>

If your compiler does not support namespaces, then you do not need the using declaration for std.

See Also

reverse_copy, swap



Previous fileTop of documentContentsIndexNext file
©Copyright 1998, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.
OEM Release, June 1998