Skip to content

Linked Lists

Pointers and dynamic memory allocation make it possible to store values in new and interesting ways. One way of structuring this data is to dynamically allocate each value, and link these together using pointers. An illustration of this is shown in Figure x.y.

Figure x.y: Illustration of a linked list in memory

Illustration of a linked list in memory

Array vs Linked List

Linked lists have the advantage of being very fast to perform insert and delete actions, when compared with arrays. The disadvantage is an increase in storage size to keep all the pointers, and the fact you must loop through the nodes to access any value in the list.

Illustration comparing arrays and linked lists

Let’s think about how we can use dynamic memory management functions to build this structure in memory.