Linked Lists


Introduction

A fixed number of data elements that have the same type can be conveniently stored in an array.  However, if you have a variable number of data elements, then an array can be inconvenient.  Imagine the difference between a text field which might allow a fixed number of characters, and how this text field might be used to develop a word processor.  How many characters should your word processor allow?  If you don't set the figure high enough, your word processor will not be able to handle large documents.  If you set the figure too high, you will waste a large amount of disk space to store small documents.  Word processors need a variable amount of storage.

When using a word processor, you should also notice that new characters are not always added at the end -- they are inserted after the cursor.  The cursor is like a "current pointer" into a (doubly) linked list of characters.  The cursor can be moved forwards and backwards along the list, and insertion and deletion of characters can only be done at the cursor.  Notice that unlike arrays, linked lists do not have "random access" -- you have sequential access, so you cannot access a random element directly.  Thus, to understand linked lists, you have to think in the perspective and limitations of your computer -- you have to learn to think like a computer.
 

Resources

Back to Main Menu