Linked Lists, Let’s Go!

Professor Riely finally went and did it… he pulled out the good ol’ Linked List from his bag of tricks and introduced you guys and girls to the dreaded pointer. Not to worry, here’s a nice and simple illustration for you on how this data structure could be viewed:

Linked List

As you can see above, each node in a liked list has two attributes: some value and a pointer referencing the next node in the list (really it’s the address of where it’s stored in memory but for our purposes we can simplify it).

As you can see, the final item holds a value – the string “mary” – and a reference to null. This reference signifies the completion of the list (e.g. there aren’t anymore associated nodes to point to).

Also, as you can see in the blue text, if you want to get started working with a given linked list, you need to begin with some variable that points to the first node in the list. This makes sense for the same reason that the last node points to null. You need something to reference something else. Isn’t that what we’re all here for???

P.S. Here’s a little illustration of how you all should be thinking about this problem you’ll be working on in your homework:


Leave a Reply

Your email address will not be published. Required fields are marked *