Member-only story

How to Implement a Linked List

Scott Cosentino
4 min readNov 3, 2019

--

A list is a data structure that is like an array in functionality. The main difference is that an array will typically have a static size, declared at the time of declaring the array. With a list, the size can grow with each insert by the user. This is helpful for situations where the amount of data we are working with is variable in size. For instance, if we are processing a CSV file with a set of records in it, the number of records a user provides might be different on every run. Rather than declaring an array to the size of the CSV, we can just insert the records without worrying about size, giving us a more efficient solution.

The implementation of a list mimics the implementation of a stack and queue. It is important to note however that a list does not have a specific storage structure, such as first in first out or last in first out. Typically, we allow the user to be able to remove at any index they like. For insertion, usually the user can insert at either the front or rear of the queue, using different methods for each. In addition to these differences, we also keep track of the length of the list, to be able to easily report it to the user, in cases where they may want to iterate the list.

To implement this functionality, we start with a Node object that is the same as a stack or queue.

The Node object

--

--

Scott Cosentino
Scott Cosentino

No responses yet