1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-08-10 03:06:58 +02:00

Add Reverse iterator (C++) (#4374)

This commit is contained in:
Mikhail Ostashchenko
2023-08-22 13:18:19 +02:00
committed by GitHub
parent 76c2686269
commit f2b29f80f9

View File

@@ -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<int> nums = {1, 2, 3, 4};
std::list<int>::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: