PDA

View Full Version : Circular QLinkedList



dyngoman
24th March 2010, 08:56
How can one create a circular linked list?One witch iterator jumps from end to begin automatically .
i.e.


QLinkedList<QObject> list;
QLinkedList<QObject>::iterator indexer;
//...
list.begin().i->p = list.end().i->n;
list.begin().i->p->t = list.end().i->t;
list.end().i->n->t = list.begin().i->t;

indexer= list.begin();
indexer++;

When indexer reaches list.end I want indexer++ to jump automatically at list.begin.
For some reason program crashes at line 5.
Is there a better solution to this problem?

high_flyer
24th March 2010, 09:57
How can one create a circular linked list?One witch iterator jumps from end to begin automatically
You will have to subclass QLinkedList, and overload the end() methods.
Be aware, that this might have implications on other methods you will have to override (as in: what happens when you delete memebers etc).


For some reason program crashes at line 5.

Returns an STL-style iterator pointing to the imaginary item after the last item in the list.