Advertising

Linked Lists

Arrays are an awkward way to store data because they can not be easily resized. Linked Lists allow the program to allocate memory as it is required.

Single-Linked Lists consist of items of data which also contain pointers to the next item of data.

Doubly-Linked Lists contain links to the next and the previous items of data. They are generally more robust.

The start and end of the list may be marked by Null pointers.

Ideally, you should deal with a Linked List class, which has methods for adding and removing items, testing if an item is present, etc.

Access time may be slower than an array, because the class must traverse the list to find an item. This can be improved by sorting the list, by adding each new item at the appropriate place.

Copyright © Murray Cumming. Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.

Murray's Web Pages