A linked list is a sequence of data structures connected through links. This means that each element in the linked list points to the next element. Linked lists are the second most used after arrays. Here are terms commonly used with a linked list.
- Link − Each link of a linked list can store data called an element.
- Next − Each link of a linked list contains a link to the next link called Next.
- LinkedList − A Linked List contains the connection link to the first link called First.
Here is an illustration of a linked list.
- Linked List contains a link element called first.
- Each link carries a data field(s) and a link field called next.
- Each link is linked with its next link using its next link.
- The last link carries a link as null to mark the end of the list.
Types of Linked List
Following are the various types of the linked list.
- Simple Linked List − Item navigation is forward only.
- Doubly Linked List − Items can be navigated forward and backward.
- Circular Linked List − The last item contains a link of the first element as next and the first element has a link to the last element as previous.
Following are the basic operations supported by a list.
- Insertion − Adds an element at the beginning of the list.
- Deletion − Deletes an element at the beginning of the list.
- Display − Displays the complete list.
- Search − Searches an element using the given key.
- Delete − Deletes an element using the given key.
In order to insert a new element into our linked list, we must take an element and have it point to our new element and then have our new element point to the previously pointed element.
In order to delete an element from our linked list, it is very similar we have to have the element that points to our element that we want to delete point to the element after it.