
On Wed, May 1, 2013 at 7:09 AM, Ion Gaztañaga
El 30/04/2013 3:00, Nat Goodspeed escribió:
On Apr 29, 2013, at 12:34 PM, Ion Gaztañaga
wrote:
There is no way to obtain the end node from a node in a circular list, as there is no runtime information stored in the ring that marks the end node.
But with a (non-empty) circular list, can't you just iterate until you return to your starting point?
The iterator does not know which node is the starting point (only the container stores a pointer to the first node). The iterator only stores a pointer to the next node, it does not know if the next node is the last or the first node as it's a circular slist.
I think the OP was talking about a function which is passed a single node without knowing its location in the circular list. I was suggesting that if the function can be sure it's a circular list, it should still be possible to iterate over all items in the list, if the function doesn't care whether it starts at the container's official "first" node.