
- [PDF]
Iterators in C++
Iterators are a generalization of pointers in C++ and have similar semantics. They allow a program to navigate through di erent types of containers in a uniform manner.
To implement the same thing using standard C++, we’ll use an object called an “iterator.” An iterator is intimately tied to a particular data structure; it provides a “view” into that data structure, giving you the …
Use an iterator An object containing an internal state variable (i.e. a pointer or index) that moves one step in the list at a time as you iterate, saving your position
A non-linear data structure defined recursively as a collection of nodes where each node contains a value and zero or more connected nodes.
Read/write element access Iterate by consumption Can’t use v afterwards Iterator adaptors
Iterators are a generalization of pointers in C++. They allow a program to navigate through different types of containers in a uniform manner.
- [PDF]
Title 1
How should we implement an iterator over a non-linear structure such as a tree? We have already discussed various tree traversals: pre-order, in-order, post-order. So, it is logical to implement …