Talk:Doubly-linked list/Element definition: Difference between revisions

Content added Content deleted
(Doubly-linked lists are better when circular)
(note: efficient doubly linked list?)
Line 4: Line 4:


:Well, this might become tricky if empty list as an object is needed. In that case to keep a pointer to the first element would of course kill the idea. A technique to handle this is to have a special head element, which does not contain any data and is never visited when data has to be accessed. Of course there there are problems too. One well known problem is a need of downcasting in an OO design. It can solved by making head element implementing the interface of other nodes with null operations, as they never called anyway. --[[User:Dmitry-kazakov|Dmitry-kazakov]] 09:24, 19 July 2008 (UTC)
:Well, this might become tricky if empty list as an object is needed. In that case to keep a pointer to the first element would of course kill the idea. A technique to handle this is to have a special head element, which does not contain any data and is never visited when data has to be accessed. Of course there there are problems too. One well known problem is a need of downcasting in an OO design. It can solved by making head element implementing the interface of other nodes with null operations, as they never called anyway. --[[User:Dmitry-kazakov|Dmitry-kazakov]] 09:24, 19 July 2008 (UTC)


===Doubly linked list===
In my experience on the AmigaOS, doubly linked list are implemented in a rather different way: there's a List header that also works like a special ''mark the end element'' of the list (implemented considering the List header like a partial superposition of two nodes, one ''shifted'' with respect to the other); so the list can be traversed in both directions, we know which is the first and the last element, and we can add fastly nodes to the head '''and''' to the tail in a rather smart and fast way. I have implemented the code (anyway it surely can be found somewhere, done better: normally it is implemented as macros, I've used functions), but I suppose that creating a new task for that will clashes with this one. --[[User:ShinTakezou|ShinTakezou]] 23:57, 8 December 2008 (UTC)