linked lists in data structure

The Linked lists are the best example of an energizing data structure that uses indicators or cursors for its execution. Therefore, knowing the cursor is crucial to knowing how linked lists work, Therefor if you have skipped the cursor session, we should go back and redo the cursor. we must also be acquired with dynamic memory share and structures.

 Advantages of linked list

  1. In linked lists, there is no need to define an initial size.
  2. In linked lists, the Items can be added or removed from the center of the list.

The disadvantage of linked lists

  1. In the linked list there is no “random” access.
  2. In linked lists, random memory allocation and pointers are required.
  3.  The Linked lists have a bigger disbursal over the array.

What are linked lists

The Arrays can be used to store linear data of similar types in a linked list is a set of random indicate nodes, ordered in such a path that each node consists of one value and one cursor. The cursor never points to another member of the list. If the cursor is NULL, then it is the last node in the list. The linked list is held using a local cursor variable which indicates the first item of the list. If that cursor is also NULL, then the list is advised (considered)  to be empty. putting the new element in an array of elements is very expensive.

in the above diagram, the linked list is represented by the pointer to the first node of the list. As the head is shown in the diagram the first node is called the head if the linked list is empty as shown in the above diagram then the linked lists are called Null, and each node in the linked lists consists of two parts as shown in the above diagram one is data and second is a pointer.

Types of linked lists

There are different types of linked lists that are as follows

  1. Singly-linked lists
  2. Double linked lists

singly linked list
Singly linked list is a way to store a collection of elements. Like an array, these elements can be characters (alphabet)  or integers. Each element in a linked list is stored in the form of a in the form the following form.

The one node is a collection of two sub-parts as the following upper diagram is shown.

The malloc( ) is used to dynamically identify  a single piece  of memory in C, it is present  in the header file stdlib.h.
The sizeof() is used to determine the size in bytes(8 bits) of an element in C. Here it is used to determine the size of every  node and sent as a parameter to malloc.
Doubly linked lists
A doubly linked list is a linked data structure that contains a set of sequentially linked records called nodes(each node contains two blocks).  and one data field in between. The beginning and ending nodes mean previous and next links, respectively, indicating some kind of terminator/ending point, typically a sentinel node or null, to facilitate traversal of the linked list. If there is one sentinel node, then the list is circularly linked via the sentinel node. It can be conceptualized as two singly linked lists formed from the same data items but in opposite sequential orders.