Movatterモバイル変換


[0]ホーム

URL:


Menu
×
Sign In
+1 Get Certified For Teachers Spaces Plus Get Certified For Teachers Spaces Plus
   ❮     
     ❯   

C++ Tutorial

C++ HOMEC++ IntroC++ Get StartedC++ SyntaxC++ OutputC++ CommentsC++ VariablesC++ User InputC++ Data TypesC++ OperatorsC++ StringsC++ MathC++ BooleansC++ If...ElseC++ SwitchC++ While LoopC++ For LoopC++ Break/ContinueC++ ArraysC++ StructuresC++ EnumsC++ ReferencesC++ PointersC++ MemoryManagement

C++ Functions

C++ FunctionsC++ Function ParametersC++ Function OverloadingC++ ScopeC++ RecursionC++ Lambda

C++ Classes

C++ OOPC++ Classes/ObjectsC++ Class MethodsC++ ConstructorsC++ Access SpecifiersC++ EncapsulationC++ Friend FunctionsC++ InheritanceC++ PolymorphismC++ TemplatesC++ FilesC++ Date

C++ Errors

C++ ErrorsC++ DebuggingC++ ExceptionsC++ Input Validation

C++ DataStructures

C++ Data Structures & STLC++ VectorsC++ ListC++ StacksC++ QueuesC++ DequeC++ SetsC++ MapsC++ IteratorsC++ Algorithms

C++ Namespaces

C++ Namespaces

C++ Projects

C++ Projects

C++ How To

C++ Add Two NumbersC++ Random Numbers

C++ Reference

C++ ReferenceC++ KeywordsC++ <iostream>C++ <fstream>C++ <cmath>C++ <string>C++ <cstring>C++ <ctime>C++ <vector>C++ <algorithm>

C++ Examples

C++ ExamplesC++ Real-Life ExamplesC++ CompilerC++ ExercisesC++ QuizC++ SyllabusC++ Study PlanC++ Certificate


C++ algorithmreverse() function

❮ Algorithm Functions


Example

Reverse the order of elements in a vector:

vector<int> numbers = {1, 3, 5, 7, 2, 9};reverse(numbers.begin(), numbers.end());for (int number : numbers) {  cout << number << " ";}
Try it Yourself »

Definition and Usage

Thereverse() function reverses the order of elements in a data range.

The range of data is specified by iterators.

Tip: To avoid modifying the data range and create a new data range instead, you can use thereverse_copy() function.

Syntax

reverse(iteratorstart, iteratorend);

Parameter Values

ParameterDescription
startRequired. An iterator pointing to the start of the data range.
endRequired. An iterator pointing to the end of the data range. Elements up to this position will be included, but the element at this position will not be.

Related Pages

Read more about data structures in ourData Structures Tutorial.

Read more about iterators in ourIterators Tutorial.

Read more about algorithms in ourAlgorithms Tutorial.


❮ Algorithm Functions

 
Track your progress - it's free!
 

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted ourterms of use,cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved.W3Schools is Powered by W3.CSS.


[8]ページ先頭

©2009-2025 Movatter.jp