Friday, 6 December 2013

Linked(In)Lists

From http://www.bloggingpro.com/wp-content/uploads/2012/06/chain.gif.
I guess linked lists are...like a chain? To be honest, I just really wanted to
add a picture to spice your life up. You're a cool person: don't forget that.
     Funny story: When I first heard of how linked lists work (you have a value, and it points to the next value in the list), I pictured each item as a tuple with the first value in it being the item at that index, and the second value being the memory address of the next thing. For example, I thought items would be like (7, 505894336) (or (7, 0x1e2755c0), since memory addresses make more sense in hexadecimal). However, a quick Google search for Python accessing things simply by their memory address results in people making comments like "Hopefully you're only doing this as an exercise. No reason to do this with pure Python." and "So in CPython, this will be the address of the object. No such guarantee for any other Python interpreter, though." Long story short: linked lists should not be implemented this way.

     I'll be honest: I've always been iffy about linked lists. I like to be able to access all the variables in a list at one time and not go hunting for them, and if you mess something up with something in the list, you've permanently lost everything after it in the list.

No comments:

Post a Comment