Iterators in C++
What are iterators useful for?
Iterators let you traverse the nodes of a linked list.
Can be categorized in 5 categories:
- Input : Sequential single pass input
- Output: Sequential single pass output
- Bidirectional: Can go in both directions backward and forward in a list.
- Forward: Can go through a list from start to finish only forward direction.
- Random Access: Allows you to use a list like a pointer and access any point in the list. Can also be considered valid bidirectional iterators.
template <class Category, class T, class Distance = ptrdiff_t,
class Pointer = T*, class Reference = T&>
struct iterator {
typedef T value_type;
typedef Distance difference_type;
typedef Pointer pointer;
typedef Reference reference;
typedef Category iterator_category;
};
Comments
Post a Comment