What are Iterators?- Iterators are the glue that hold the container and algorithms together. They provide an abstract view of data so that the writer of algorithm need not be concerned with concrete details of a myriad of data structures. - At the same time, the standard model of data access provided by iterators relieves the containers from having to provide a more extensive set of access operations. - An iterator is simply an abstract of the notion of a pointer to an element of a sequence. - The key concepts of iterator are :
i. The element currently pointed to. ii. Point to next element. iii. Equality.
- The iterator classes and functions are declared in namespace std and found in <iterator>. - The iterator is not a general pointer. Hence there is no concept of ‘null iterator’. The test is to determine whether an iterator points to an element or not is done by comparing it against the end of its sequence. An iterator which points to an element is said to be valid and can be dereferenced using *, [] or →.
|