r/learnprogramming • • Jan 31 '14

Can someone ELI5 linked lists?

Part of my assignment for my online class involves linked lists and we don't really go over them. I looked around online and I'm slightly confused by all the explainations since I'm fairly new to programming. Can someone dumb it down for me?

77 Upvotes

85 comments sorted by

View all comments

Show parent comment

4

u/DestroyerOfWombs Jan 31 '14

Well, I and NIST disagree, here is what NIST says: linked list Definition: A list implemented by each item having a link to the next item. [1] It stores a link to a next item, it doesn't define underlying structure or anything else for that matter...

Yes it does, because NIST's definition of link is

A reference, pointer, or access handle to another part of the data structure. Often, a memory address.

Which specifically deals with memory. Note that none of the criteria are an actual physical or spacial link, it is entirely defined as an address. The link in your metaphor is physically touching, you can follow it by following the rope. This is a great example for an array structure, but you'll never across a real world example where the next item in a linked list would be physically after the previous node. I can't imagine any circumstance where you would be dealing with linked lists outside of the context of memory since their whole purpose is a way of storing data in memory. The source you linked even suggests that on the very page when it says

Note: The first item, or head, is accessed from a fixed location, called a "head pointer."

Since a pointer is just a memory address, I think we can safely put this issue to bed.

-1

u/[deleted] Jan 31 '14 edited Feb 01 '14

but you'll never across a real world example where the next item in a linked list would be physically after the previous node.

It doesn't have to be. I never said that linked lists are restricted in way you described. The arrays are, but the question is not about the arrays.

I can't imagine any circumstance where you would be dealing with linked lists outside of the context of memory since their whole purpose is a way of storing data in memory

The point of linked list(and any DS) for that matter is 'S'tructuring data, not the concrete implementation and storing data, but you knew that, right?