Linked Lists – What They Are and How to Use Them

Most, if not all, programmers have at least heard of a linked list. If you have not then you are about to. In this article I will be outlining what exactly a linked list is, the advantages of using one, and I will try to do this in the simplest terms that I can.

So, lets get to the point. When you are programming, it is a very common occurrence that you want to keep track of a list or set of data. The easiest way to do this is with an array. Whether it is a single dimensional, or more gridlike 2-3 dimensional array, it will typically suite your needs just fine.

But, what do you do when you have an array of say, a million items. Naturally this is going to take up quite a bit of memory. Still, an array will probably do the job just fine. So now lets look at Object Oriented Programming (OOP). Maybe you want to create an array of Objects, each with a fair number of variables. This memory adds up quite fast. And to make things worse, an array of memory is all contiguous; the memory is all in one solid chunk.

A way around this solid chunk of memory is, yes you guessed it, a linked list. The beauty of a linked list is that it does not have to have contiguous memory. The different objects, typically called nodes, each contain a link variable. This link points to the next item in the list, where it may be in memory. Think about it kind of like a puzzle. You typically would not store a puzzle completely built because those "contiguous pieces" are bulky and hard to store; and if you wanted just one you've got to take them all. So instead, you break the puzzle apart, because you know each piece link to the next one piece. This way you can work with just the piece you want and still keep track of the rest.

Another great advantage to linked lists is that they are customized to exactly what you want. A linked list is not typically something included in a programming language, it is something that you build yourself. This may be a bit bit more difficult than using an array, or even an arrayList, but it proves itself in power.

If anyone has any questions about Linked Lists, feel free to ask on the forum. Either I will help you personally or someone else will.