[Tutor] linked list with cycle structure

A.T.Hofkamp a.t.hofkamp at tue.nl
Wed Jan 7 12:46:07 CET 2009


David Hláčik wrote:
> Hello guys,
> 
> I have a linked list where *number of elements is unlimited* and
> **last element points on random (can be first, last, in middle ,
> anywhere) element within linked list** - this is important . My goals
> is to create an architecture /scheme for **algoritmus which will count
> total number of elements** of such linked list.
> Yes , maybe it sounds strange, but we need to implement this and i
> would be very gladfull for your toughts.

Python supplies a list data structure for you, so in 'normal' Python, you 
wouldn't bother with linked lists and all the assoicated problems.

However, if you really want:
Make a class for a list-element, with a next/prev variable (if you have a 
double-linked list).
Instantiate as many objects as you like from that class, and let the next/prev 
variables from one object refer to other objects that you instantiated.
(Python doesn't care where a variable refers to.)

For the NULL value you can use None.


Sincerely,
Albert



More information about the Tutor mailing list