The Linked List Versus the Array

Many programming problems, such as creating a list or a queue, can be handled with a linked list—by which we mean a linked sequence of dynamically allocated structures—or with an array. Each form has its strengths and weaknesses, so the choice of which to use depends on the particular requirements of a problem. Table 17.1 summarizes the qualities of linked lists and arrays.

Table 17.1. Comparing arrays to linked lists.
Data FormProsCons
ArrayDirectly supported by C time Provides random accessSize determined at compile time
  Inserting and deleting elements is time-consuming
Linked ListSize determined during runtimeNo random access
 Inserting and deleting elements is quickUser must provide programming support

Take a ...

Get C Primer Plus®, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.