Assuming the linked list is defined this way:
template <typename Object>
struct Node{
Object data;
Node *prev;
Node *next;
Node(const Object & d = Object(), Node *p = NULL, Node *n = NULL)
: data(d), prev(p),next(n){}
};
template <typename Object>
class List
{
public:
iterator begin(){return iterator(head->next);}
iterator end(){return iterator(tail);}
....
private:
Node *head=nullptr;
Node *tail=nullptr;
...
The iterators:
class iterator
{
public:
iterator():current(NULL){}
Object & operator*(){return retrieve();}
iterator & operator++()
{
current = current->next;
return *this;
}
....
private:
Node *current;
...
There is a problem in this code.
for(iterator<Object> itr = list.begin(); itr != list.end(); itr++ )
std::cout<<(*itr)->name;
This loop counts until the one item member before the last one. So, the last member of this list is not counted in this loop. How to fix it?