Chapter: Programming and Data structures : C++ Programming Advanced Features

Iterators

An iterator is an object that points to an element in a container. We can use iterators to move through the contents of containers. Iterators are handled just like pointers.

ITERATORS:

 

An iterator is an object that points to an element in a container. We can use iterators to move through the contents of containers. Iterators are handled just like pointers.

 

Iterators are classified into five categories depending on the functionality they implement:

 

       Input

       Output

       Forward

       Bidirectional

       Random Access

 

Input and output:

 

Input and Output iterators are the most limited types of iterators: they can perform sequential single-pass input or output operations.

 

Forward:

 

Forward iterators have all the functionality of input iterators and if they are not constant iterators also the functionality of output iterators, although they are limited to one direction in which to iterate through a range (forward). All standard containers support at least forward iterator types.

 

Bidirectional:

 

Bidirectional iterators are like forward iterators but can also be iterated through backwards.

 

Random Access:

 

Random-access iterators implement all the functionality of bidirectional iterators, and also have the ability to access ranges non-sequentially: distant elements can be accessed directly by applying an offset value to an iterator without iterating through all the elements in between. These iterators have a similar functionality to standard pointers (pointers are iterators of this category).


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Programming and Data structures : C++ Programming Advanced Features : Iterators |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.