The std :: list class creates a circular list. When I create an iterator to go through I find myself with an ambiguous situation, which I exemplify:
#include<iostream>
#include<list>
using namespace std;
int main()
{
list<int> lista;
lista.push_back(3);
lista.push_back(6);
lista.push_back(9);
list<int>::iterator it;
it=lista.begin();
for(int i=0;i<10;i++)
{
cout << (*it);
it++;
}
return 0;
}
In this case we will get the following output:
3693369336
That is, in the last position if I advance I will stop at the node "end" which, from what I understand is again the first in the list. Is there another way to prevent this last / first (sort of a header node) from repeating the list circularly without walking with additional conditions?