I wrote my own container class whose original internal data structure was std::list. Then I needed to create my own double list. I have now implemented my own double-linked list, as well as my own iterator for the linked list, but I am having problems making it behave like std::list, especially with begin()and end().
From what I understand, the begin()first node end()should indicate , and should indicate one element after the last element. I need to make sure that when I call end(), I can return to the actual last element. I also need to make sure that I can do your usual workarounds, for example ...
while (beg != end ) { do something; beg++; }
Essentially, my linked list simply uses nodes that contain the data item, a pointer to the previous node, and a pointer to the next node.
When I first tried to implement mine end(), I had only the last node, the next pointer be a nullptr. It works on its own, but does not act like stl.
Any tips on how to implement begin()and end()just like the standard library does?
source
share