K
kazio
Hello,
So, I need to have double linked, circular list (last element point to the
first one and first one points to the last one). I thought maybe I could
use list container from STL, but unfortunately probably not. I checked it,
and when I increase (++) iterator pointing to the last element the program
crashes.
I know the standard says, this is a linear list (with beginning and the
end), but I completely don't understand why they designed (limited) it so.
I also studied quite carefully the source for my STL list implementation
(gcc), and I think it is actually a circular list, and there is connection
between last and first element (LastElem->next == FirstElem and FirstElem->prev ==
LastElem), so I really don't understand:
1) why the iterator cannot go further after the last element
2) and actually what does it mean, that iterator returned from end()
points to "the element after the last one"? After my study of gcc implementation of list
this should just return the last one. And begin() should return
LastElem->next which means the first one, as expected from this circular
list.
Maybe I'm missing something important in my investigation process, please
help me.
A general question is:
Can I use the STL list (maybe after some modifications) as a circular
list, if not are there somewhere ready circular list libraries (compatible
with STL) or should I write one for myself from scratch?
Thank you very much
Kazimierz
So, I need to have double linked, circular list (last element point to the
first one and first one points to the last one). I thought maybe I could
use list container from STL, but unfortunately probably not. I checked it,
and when I increase (++) iterator pointing to the last element the program
crashes.
I know the standard says, this is a linear list (with beginning and the
end), but I completely don't understand why they designed (limited) it so.
I also studied quite carefully the source for my STL list implementation
(gcc), and I think it is actually a circular list, and there is connection
between last and first element (LastElem->next == FirstElem and FirstElem->prev ==
LastElem), so I really don't understand:
1) why the iterator cannot go further after the last element
2) and actually what does it mean, that iterator returned from end()
points to "the element after the last one"? After my study of gcc implementation of list
this should just return the last one. And begin() should return
LastElem->next which means the first one, as expected from this circular
list.
Maybe I'm missing something important in my investigation process, please
help me.
A general question is:
Can I use the STL list (maybe after some modifications) as a circular
list, if not are there somewhere ready circular list libraries (compatible
with STL) or should I write one for myself from scratch?
Thank you very much
Kazimierz