Table of Contents
The recursive traversal algorithms work well for implementing
tree-based ADT member functions, but if we are trying to hide the trees
inside some ADT (e.g.,
std::set), we may need to provide
iterators for walking though the contents of the tree.
Iterators for tree-based data structures can be more complicated than those for linear structures.
For arrays (and vectors and deques and other array-like structures) and linked lists, a single pointer can implement an iterator:
Given the current position, it is easy to move forward to the next element.
For anything but a singly-linked list, we can also easily move backwards.