Introduction - What Are Linked Lists?
Arrays and Linked Lists are the two fundamental types of data structures in programming, and every other advanced data structure is some form of array or linked list (or at least borrow the concept). An array is a contiguous block of memory reserved for holding data, but linked lists contain one data point, and have a pointer to another place in memory for the next data point.
Why Use A Linked List Instead Of An Array?
So why use a Linked List instead of an array? Let's go through some reasons.
Why Linked Lists Are Good:
Why Linked Lists Are Bad (And Why Arrays Are Good):
Singly And Doubly Linked Lists
There are two types of linked lists (sort of).
A singly linked list has a single pointer from one data point to the next data point in the list.
A doubly linked list contains not only a pointer to the next data point, but also contains a pointer to the previous data point.
Linked List C++ Code (Creation and Traversal)
Here's some code to show how Linked Lists work in C++.
The hardest thing about the code is keeping track of the pointers. Remember, create a new node with the new keyword. We need the node to show up on the heap.
Linked Lists are often overlooked in favor of arrays, stacks, queues, etc., but they're fundamental to understand and very popular in interview questions.
We'll look at some popular linked list questions in future blog posts.
Hi, I'm srcmake. I play video games and develop software.
Pro-tip: Click the "DIRECTORY" button in the menu to find a list of blog posts.
License: All code and instructions are provided under the MIT License.