Linked lists in C belong to the basic concepts of C programming. Essentially, linked lists are similar to arrays, but developers emphasize several differences between them. For instance, you cannot add or delete values from the middle of an array. Additionally, linked lists do not require you to provide an initial size. Instead, they are dynamically allocated.
Another significant difference is that linked lists in C are not continuous, meaning that they can be scattered in the memory. Such lists also have pointers, which point to another node in the collection. In this linked lists tutorial, I will show you how to define and how to use linked lists, the sets of dynamically allocated nodes. For instance, the first lecture in the second section focuses on the meaning of linked lists and shows how you can create their structure in C.
By definition, C linked lists have several unique components. First of all, linked lists are sets of nodes. As a rule, each node has a value and a pointer, leading to the next node. When the pointer is NULL, it means that the node is the last in the linked list. Seems pretty straightforward, right? But what are the advantages of these structures?
No need to pre-allocate memory. As your linked list gets new elements, the memory automatically updates. The same applies to removing elements from a linked list.
It is easier to add or remove elements from the list. When you create an array, you define its size. Therefore, if you set the array size to four, you can only have four elements in that array. To add a fifth, you would need to create a new array with a bigger size and move those elements to it. Because of the dynamic memory allocation, linked lists in C do not have such an issue.
While C linked lists offer benefits, they usually take up more space due to the additional pointers. Furthermore, it is more challenging to access elements since we have to traverse all the elements that come before the one we need. In arrays, you can search for elements by their index.
This linked lists tutorial discusses the singly linked lists and doubly linked lists in separate sections. The main difference to note is that singly linked lists only have one pointer, while doubly linked lists have two. Therefore, doubly linked lists are more memory-consuming, but I will aim to explain their purpose, and when it is better to use a singly linked list instead.
In this course on linked lists in C, I will show how to use linked lists to get you more comfortable in applying them to your programs. For my lectures, I hope that you have some knowledge about C programming, pointers, and other similar concepts. I start by explaining singly linked lists: how to iterate them, insert or remove elements, reverse, detect loops/cycles, and count elements. The same operations are going to be explained for the doubly linked lists.
Top graduate at one of the best Universities in Romania. Having noticed the struggle fellow colleagues have been going through to learn new topics, I started pursuing teaching as my main profession.
I have worked on many projects in many of the popular languages and frameworks out there. Having such broad experience from all over the IT field and knowing how to make people understand and learn, I decided to become the go-to person for people that are struggling to learn a new subject.
Life goal: change the education system for the better.