mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-01-17 22:28:32 +01:00
Add Reverse iterator (C++) (#4374)
This commit is contained in:
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.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user