c++listiterator

Need help coding iterator for a circular linked list in C++


So I'm creating a circular linked list to solve the Josephus Problem for an assignment. I had a really bad professor for my C++ class and I don't really know how to do anything in C++. I'm trying to code an iterator to transverse the list, but I have no clue where to start or how to implement it. Can anyone give me an suggestions or advice on how to start coding this?


Solution

  • It's pretty much just like the std::list iterator, except the end iterator is where the next pointer is the head of the list, not when it's NULL. A reference page will tell you what you're supposed to implement. The underlying representation will be a pointer to a list node, operator* will return a reference to the data, operator++ will set the pointer to next, etc.

    Alternatively, use an array implementation with modular arithmetic.