An in-depth exploration of iterators in object-oriented programming (oop), their definitions, and categories, including input iterators, output iterators, forward iterators, bidirectional iterators, and random-access iterators. Understand their capabilities and container compatibility.
Download Object-Oriented Programming (OOP) Lecture 42: Iterators and Their Categories and more Slides Object Oriented Programming in PDF only on Docsity!
Object-Oriented Programming
(OOP)
Lecture No. 42
Iterators
Iterators are types defined by STL
Iterators are for containers like pointers are for ordinary data structures
STL iterators provide pointer operations such as * and ++
Input Iterators
Can only read an element
Can only move in forward direction one element at a time
Support only one-pass algorithms
Output Iterators
Can only write an element
Can only move in forward direction one element at a time
Support only one-pass algorithms
Bidirectional Iterators
Provide all the capabilities of forward iterators
In addition, they can move in backward direction
As a result they support multi-pass algorithms
Random Access Iterators
Provide all the capabilities of bidirectional iterators
In addition they can directly access any element of a container
Container and Iterator Types
Sequence Containers -- vector -- random access -- deque -- random access -- list -- bidirectional