How can I create a linked list in Python?

Hendrik van Rooyen mail at microcorp.co.za
Fri Jan 19 09:09:41 EST 2007


"Jorgen Grahn" <grahn+nntp at snipabacken.dyndns.org> wrote:

> 
> FWIW, I oppose the idea (paraphrased from further up the thread) that linked
> lists and other data structures are obsolete and dying concepts, obsoleted
> by Python and other modern languages.
> 
> 99% of the time. a Python list is the right tool for the job, but that's
> only because we have CPU cycles to spare and the 'n' in our 'O(n)' is
> limited. You cannot call yourself a computer scientist without understanding
> things like linked lists.  No other data structure has the same
> characteristics (good and bad) as that one. Or those two, really.

+1

The concept of storing a pointer that points to the "next thing" is so basic
that it will never go away.  One meets it all time in chained buffer blocks, 
in tag sorts, etc...

And if you add a pointer to the "previous thing" too, then adding or taking
something out of what could become a ring is a constant effort.  Until you
run out of memory.

Ye Olde Universal Controlle Blocke:

- pointer to the start of data block
- length of allocated data block
- pointer to next control block
- pointer to previous control block
- next in pointer into data block
- next out pointer into data block
- optional length of data
- optional here starts or ends the lesson indicator

errrm... thats about it, unless you want a fast index too:

- pointer to first control block
- pointer to second control block
- pointer to third control block
...

Isn't it nice of python to hide all this stuff?

- Hendrik





More information about the Python-list mailing list