I wrote the following code when trying to create a doubly linked list with an internal STL-like iterator. I will just put the header file with non-relevant parts truncated at the moment.
My questions...
STL uses iterators in a certain way - in particular, you navigate the STL container from the .begin () iterator to, but not including the .end () iterator. To do this, the .end () iterator must be one after the end of the container. How would I implement this semantics based on what I started with (this is the main question)?
Is there anything in the interface that stands (regarding the iterator class and what should be present in it)?
Here is the code:
template <typename T> class Node { T data; Node<T>* next; Node<T>* prev; }; template <typename T> class LinkedList { public: class Iterator { public: Iterator() {} explicit Iterator(const Node<T>& init) { current = init; }
I know that I may or may not have problems with ++ / - operators, but this doesnβt bother me much, since I will work with them when I have enough code to carry out some tests on this, Do not hesitate to throw hints although if you are inclined :)
source share