From f2b29f80f9fb011480de76da081ed5d7bdf088ee Mon Sep 17 00:00:00 2001 From: Mikhail Ostashchenko Date: Tue, 22 Aug 2023 13:18:19 +0200 Subject: [PATCH] Add Reverse iterator (C++) (#4374) --- .../roadmaps/cpp/content/110-stl/100-iterators.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/data/roadmaps/cpp/content/110-stl/100-iterators.md b/src/data/roadmaps/cpp/content/110-stl/100-iterators.md index c95955f1f..c83ae9c34 100644 --- a/src/data/roadmaps/cpp/content/110-stl/100-iterators.md +++ b/src/data/roadmaps/cpp/content/110-stl/100-iterators.md @@ -37,6 +37,19 @@ while (itr != nums.end()) { } ``` +**Reverse Iterator**: Similar to input iterators but can be used for multiple passes over the elements in a container. They cannot move forward. + +Example: + +```cpp +std::list nums = {1, 2, 3, 4}; +std::list::reverse_iterator itr = nums.rbegin(); +while (itr != nums.rend()) { + std::cout << *itr << " "; + ++itr; +} +``` + - **Bidirectional Iterator**: These iterators offer the ability to move both forward and backward in a container. List and set containers have bi-directional iterators. Example: @@ -78,4 +91,4 @@ for (auto itr = nums.begin(); itr != nums.end(); ++itr) { } ``` -When working with algorithms, remember that the C++ Standard Library provides various algorithms that already utilize iterators for tasks like searching, sorting, and manipulating elements. \ No newline at end of file +When working with algorithms, remember that the C++ Standard Library provides various algorithms that already utilize iterators for tasks like searching, sorting, and manipulating elements.