Introduction to Linked List

If you have studied C programming then you must have been familiar with arrays. You know that arrays store data one after another, like people standing in a line. In C programming, there is another data structure called linked list. It is similar to array but works differently from arrays.

Linked list is a method of storing data, different data like (number, text etc.) are stored in different nodes. These nodes store the data of their own node and store the address of other nodes through which we can access the data of other nodes very easily.

Introduction to Linked List

Structure of Linked List

A node is made up of two parts:
  1. Data: Holds any value such as: 5, 10, “Hello”
  2. Next: This is a pointer that stores the address of the next node.
The node at the end of the program does not point to the address of any node, so NULL means zero.

Why Learn Linked List?

Limitations of array:-
  • Fixed Size: The size of an array is already given, so increasing or decreasing the size later becomes very complicated.
  • Insert/Delete: If you want to add or delete data from the middle of an array, you have to shift all the data, which becomes very complicated.
Advantage of Linked List:
  • Dynamic Size:Create as many notes as you need, there is no size limit if there is linked list memory.
  • Insert/Delete:If you change the links, you can easily add or remove nodes.
Introduction to Linked List

Example

Suppose we store the numbers 3, 5, and 9 in a linked list.
  1. The first node with data = 3 and Next will point to the second node.
  2. The second node whose data = 5 and Next will point to the third node.
  3. The third node with data = 9 and next = NULL because it is the last node
Introduction to Linked List

Types of Linked List

  • Singly Linked List: What we’ve discussed so far is this linked list.
  • Doubly Linked List: Here each node has the address of both the back node and the front node. As a result, the data of the front node and the data of the back node can be accessed very easily.
  • Circular Linked List: Here the last node points to the first node, creating a circular loop.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *