mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-08-11 19:53:59 +02:00
Add Reverse iterator (C++) (#4374)
This commit is contained in:
committed by
GitHub
parent
76c2686269
commit
f2b29f80f9
@@ -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.
|
- **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:
|
Example:
|
||||||
|
Reference in New Issue
Block a user