×

Linked List Data Structure

Linked list in DS: The linked list is a non-primitive and linear data structure. It is a list of a particular type of data element that is connected to each other, as shown in the figure.

Linked List Data Structure

The linked list represents the group of nodes in which each node has two parts. The first part represents the data, and the second part represents the pointer. The pointer part of the linked list holds the address of the next node. A linked list is a data structure whose length can be increased or decreased dynamically (in run-time). The linked list is used to create a tree and graph.

Operations of Linked list

There are following types of operations in the linked list:

  1. Creation operation: It is used to create a new node in the linked list.

Node creation function:

struct node   {      int data;       struct node *next;  };  struct node *head, *ptr;   ptr = (struct node *)malloc(sizeof(struct node *));     
  • Insertion operation: It is used to add a new node to a particular location in a specific situation. A new node can be inserted at the following locations.
  • At the beginning of the linked list
  • At the middle of the linked list
  • At the end of the linked list
  • Deletion operation: It is used to delete a node in a specific situation. A node can be deleted from the following locations.
  • At the beginning of the linked list
  • At the middle of the linked list
  • At the end of the linked list
  • Traversing Operation: This operation is used to print the values ??from a node point to another node point. In other words, traversing operations is a process in which all the nodes of a linked list are checked end-to-end. If traversing from the first node to the last node, it is called forward traversing.

The following code represents the traversing of a node in the linked list:

  void traverse(node   *head){if(head != NULL){traverse (head ->   next);printf(“%d”, head   -> data);}}
  • Display Operation: The display operation is used to print the information of each node. This operation displays the complete list of nodes.
  • Search Operation: The search operation is used to search a particular node in a linked list. A sequential search is most commonly used to search the nodes in a linked list.
  • Concatenation Operation: This operation is used to connect a node to another node in the linked list.

Representation of Linked List in the Memory

The linked list is stored in different locations in the memory. The memory is allocated dynamically for each node. Dynamic means that it is allocated when it is needed. Due to the dynamical allocation, the user can increase and decrease the size of the linked list whenever he wants. An example of a memory representation in a linked list is shown in the figure below.

Linked List Data Structure

Related Topics

Binary tree insertion

As we all know, a binary tree has a maximum of two children and helps us manage the info correctly. Here the name of the tree itself portrays the mechanism...

4 minutes read.

Finding the Sum of All Paths in a Binary Tree

Implementation // Writing the C++ program to implement the below approach.  #include <bits/stdc++.h> using namespace std; // creating the new tree node structure. struct Tree__nod { int val; Tree__nod *Lft, *Rt; }; // creating a new function that will...

8 minutes read.

Linear vs Circular Queue: Data Structure

Difference Between Linear and Circular Queue What is Linear Queue? A linear queue is linear data structure which works on first in first out principle. We can say a linear queue is...

3 minutes read.

What Is Dfs Algorithm in Data Structures

DFS stands for Depth First Search. Generally, it is a repetitive or decidable type of algorithm which is basically used in identifying all the vertices or nodes of a graph...

5 minutes read.

Pairwise swap elements of a given linked list

Pairwise swap elements of a given linked list In this problem, we have given a linked list, and we need to pairwise swap elements of the given linked list. Example:                                     Input:1 ->3...

4 minutes read.

Length of longest palindrome in a linked list using O(1) extra space

Length of longest palindrome in a linked list using O(1) extra space In this problem, we need to find the length of the longest palindrome list that is present in given...

2 minutes read.

Program to calculate the area of the circumcircle of an equilateral triangle

You have given one value which represents the side of the equilateral triangle. You have to find out the area of the circumcircle. Let’s take an example - For the above...

3 minutes read.

Delete N nodes after M nodes of a linked list

Delete N nodes after M nodes of a linked list In this problem, we have given a linked list and two integers M and N. We need to traverse the linked...

3 minutes read.

Primitive Data Structure in C

The data structure is a logical or mathematical model for organizing and structuring the main memory or elements. We can classify the data structures in two ways one is primitive, and...

10 minutes read.

Right side view of binary tree

The right view of the binary tree is generally known to be that side viewed from the right direction of the point of view. To be more precise, the right-side...

8 minutes read.

Identical Linked Lists

Identical Linked Lists In this problem, we have given two linked lists, and we need to check whether the given linked lists are identical or not. Identical means they have the...

4 minutes read.

AVL Tree

AVL Tree AVL Tree is referred to as self-balanced or height-balanced binary search tree where the difference between heights of its left subtree and right subtree (Balance Factor) can't more than...

25 minutes read.

Binary tree deletion

This article will discuss the deletion operation's implementation in the binary tree. The deletion operation helps us eliminate an element from the tree. Implementation #include <bits/stdc++.h> using namespace std; /* A binary tree node...

4 minutes read.

Circular Queue

Circular Queue Circular Queue is special type queue, which follows First in First Out (FIFO) rule and as well as instead of ending queue at the last position, it starts again...

4 minutes read.

Operations on Queue in Data Structures

A queue is a linear structure where operations are done in a specific sequence. Queues are abstract data structures that are comparable to Stacks. A queue, unlike a stack, is...

8 minutes read.

Deque in Data Structure

Deque A deque referred as “Double-Ended Queue”, is a linear collection of data items same like queue data structure. deque has two ends, front end and rear end, deque is the...

27 minutes read.

Buffer overflow attack with examples

You have undoubtedly faced the term buffer overflow in your programming journey. Many times it occurs when we try to run a piece of code with user input, but it...

4 minutes read.

Splay Tree

Splay Tree A splay tree is a self-balanced or self-adjusted binary search tree. We can say, Splay Tree is used in some cases where some elements or data are accessed more...

8 minutes read.

Balanced Binary Tree

A balanced binary tree is just a random nod-based tree with a rule of keeping its height minimum in size to maintain various operations such as insertions, deletions and several...

3 minutes read.

Serialize and Deserialize Binary Trees

In order to save a tree in a file that can later be restored, serialisation is used. The tree's structure must be preserved. Deserialization involves reading a tree from a...

4 minutes read.