Disclaimer: This is a user generated content submitted by a member of the WriteUpCafe Community. The views and writings here reflect that of the author and not of WriteUpCafe. If you have any complaints regarding this post kindly report it to us.

Most, if not all, programmers have at least heard of a linked list c++. If you haven't 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's 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 doesn't 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, wherever it may be in memory. Think about it kind of like a puzzle. You typically wouldn't store a puzzle completely built because those “contiguous pieces” are bulky and hard to store; and if you wanted just one you'd have to take them all. So instead, you break the puzzle apart, because you know each piece links to the next piece uniquely. 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 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 little bit more difficult than using an array, or even an arrayList, but it proves itself in power.

0

0

Login

Welcome to WriteUpCafe Community

Join our community to engage with fellow bloggers and increase the visibility of your blog.
Join WriteUpCafe