envirementalb Logo
envirementalb Logo

linked lists in data structure

The Linked lists are the best example  of a energizing  data structure that uses indicators or cursor for its execution. Therefore, knowing cursor  is crucial to knowing  how linked lists works, 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.

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 more  bigger disbursal over array.

What is linked lists

The Arrays can be used to store linear data of similar types in  linked list is a set of random  indicate  nodes, ordered in such the path that each node consists  one value and one cursor. The cursor ever points to the 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 indicate to 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 head if the linked lists is empty as the shown in the above diagram then the linked lists is 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 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 the  way to store a collection of elements. Like an array these elements  can be character (alphabet)  or integers. Each element in a linked list is stored in the form of a node.is in the form 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 size in bytes(8 bits) of an element in C. Here it is used to determine size of every  node and sent as a parameter to malloc.
Doubly linked lists
Doubly linked list is  a linked data structure that contains  of a set of sequentially linked records called nodes(each node is contain the  two blocks).  and one data field in between. The beginning and ending nodes’mean  previous and next links, respectively, indicates  to some kind of terminator/ending point, typically a sentinel node or null, to facilitate traversal of 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.