Linked lists
While using the List
generic class, you can easily get access to particular elements of the collection using indices. However, when you get a single element, how can you move to the next element of the collection? Is it possible? To do so, you may consider the IndexOf
method to get an index of the element. Unfortunately, it returns an index of the first occurrence of a given value in the collection, so it will not always work as expected in this scenario. Fortunately, linked lists exist and can help you with this problem! In this section, you will learn about a few variants.
Singly linked lists
A singly linked list is a data structure in which each list element contains a pointer to the next element. Thus, you can easily move from any element to the next one, but you cannot go back. Of course, the last element in the list has an empty pointer to the next element because there is nothing more located in the list.
Imagine a singly linked list
If you want to better...