Search

Home > Take Up Code > 45: Collections: Iterators Part 1.
Podcast: Take Up Code
Episode:

45: Collections: Iterators Part 1.

Category: Technology
Duration: 00:11:37
Publish Date: 2016-01-26 23:22:19
Description:

Iterators give you the ability to navigate from one item to another in a collection. Why is this so special? Now that you know how to work with various collections, you know that they’re structured very differently. An array just needs to move a pointer to the next item. A list needs to follow wherever the next pointer leads. A binary tree needs to go up and down the tree. Iterators give you a common way to navigate no matter what kind of collection you’re using.

If you have a collection like this:

list myNumbers;
Then you can access the first number in the list like this:
auto beginIter = myNumbers.begin();
And you can access the end iterator like this:
auto endIter = myNumbers.end();
Then you can create a for loop to process items in the list like this:
for (; beginIter != endIter; ++beginIter)
{
    // Add your code here.
}
Total Play: 0

Some more Podcasts by Take Up Code

300+ Episodes