Last Updated : 23 Jul, 2025
A singly linked list is a fundamental data structure, it consists of nodes where each node contains a data field and a reference to the next node in the linked list. The next of the last node is null, indicating the end of the list. Linked Lists support efficient insertion and deletion operations.
Understanding Node StructureIn a singly linked list, each node consists of two parts: data and a pointer to the next node. This structure allows nodes to be dynamically linked together, forming a chain-like sequence.
C++
// Definition of a Node in a singly linked list
struct Node {
// Data part of the node
int data;
// Pointer to the next node in the list
Node* next;
// Constructor to initialize the node with data
Node(int data)
{
this->data = data;
this->next = nullptr;
}
};
C
// Definition of a Node in a singly linked list
struct Node {
int data;
struct Node* next;
};
// Function to create a new Node
struct Node* newNode(int data) {
struct Node* temp =
(struct Node*)malloc(sizeof(struct Node));
temp->data = data;
temp->next = NULL;
return temp;
}
Java
// Definition of a Node in a singly linked list
public class Node {
int data;
Node next;
// Constructor to initialize the node with data
public Node(int data)
{
this.data = data;
this.next = null;
}
}
Python
# Definition of a Node in a singly linked list
class Node:
def __init__(self, data):
# Data part of the node
self.data = data
self.next = None
JavaScript
// Definition of a Node in a singly linked list
class Node {
constructor(data) {
// Data part of the node
this.data = data;
this.next = null;
}
}
In this example, the Node class contains an integer data field (data) to store the information and a pointer to another Node (next) to establish the link to the next node in the list.
1. Traversal of Singly Linked ListTraversal in a linked list means visiting each node and performing operations like printing or processing data.
Step-by-step approach:
current
) to the head of the list.while
loop until current
becomes NULL
.current = current->next
.2. Searching in Singly Linked ListTo read more about Traversal Operation in linked list Refer, Traversal of Singly Linked List
Searching in a Singly Linked List refers to the process of looking for a specific element or value within the elements of the linked list.
Step-by-step approach:
NULL
) is reached.3. Length of Singly Linked ListTo read more about Searching Operation in linked list Refer, Search an element in a Linked List
Finding the length of a Singly Linked List means counting the total number of nodes.
Step-by-step approach:
length = 0
).current
.length
for each node.current = current->next
).length
when current
becomes NULL
.4. Insertion in Singly Linked ListTo read more about Finding Length of linked list Refer, Find Length of a Linked List
Insertion is a fundamental operation in linked lists that involves adding a new node to the list. There are several scenarios for insertion:
a. Insertion at the Beginning of Singly Linked List: Insertion at the beginning involves adding a new node before the current head, making it the new head.
Insert a Node at the Front/Beginning of Linked ListStep-by-step approach:
To read more about Insertion at the Beginning of linked list Refer, Insert a Node at Front/Beginning of a Linked List
b. Insertion at the End of Singly Linked List: To insert a node at the end of the list, traverse the list until the last node is reached, and then link the new node to the current last node
Insertion at end of Linked ListStep-by-step approach:
To read more about Insertion at the end of linked list Refer, Insert Node at the End of a Linked List
c. Insertion at a Specific Position of the Singly Linked List: To insert a node at a specific position, traverse the list to the desired position, link the new node to the next node, and update the links accordingly.
Step-by-step approach:
next
to the current head.(position - 1)ᵗʰ
node (just before the desired position).next
to the next node of the current position.next
to the new node.5. Deletion in Singly Linked ListTo read more about Insertion at the specific position of linked list Refer, Insert a node at a specific position in a linked list
Deletion involves removing a node from the linked list. Similar to insertion, there are different scenarios for deletion:
a. Deletion at the Beginning of Singly Linked List: To delete the first node, update the head to point to the second node in the list.
Deletion at beginning in a Linked ListSteps-by-step approach:
To read more about Deletion at the beginning in linked list Refer, Deletion at beginning (Removal of first node) in a Linked List
b. Deletion at the End of Singly Linked List: To delete the last node, traverse the list until the second-to-last node and update its next field to None.
Deletion at the end of linked listStep-by-step approach:
To read more about Deletion at the end in linked list Refer, Deletion at end (Removal of last node) in a Linked List
c. Deletion at a Specific Position of Singly Linked List: To delete a node at a specific position, traverse the list to the desired position, update the links to bypass the node to be deleted.
Delete a Linked List node at a given positionStep-by-step approach:
6. Modify a Singly Linked ListTo read more about Deletion at the specific position in linked list Refer, Delete a Linked List node at a given position
Updating in a Singly Linked List means modifying the value of a node at a given position.
Step-by-step approach:
current
node to position
).7. Reversing a Singly Linked ListTo read more about Updation Operation in Linked List Refer, Modify contents of Linked List
Reversing a singly linked list means changing the direction of pointers so that the last node becomes the new head.
Step-by-step approach:
prev = NULL
(to track the previous node)current = head
(starting point)next = NULL
(to store the next node temporarily)next = current->next
(save next node).current->next = prev
.prev
and current
forward (prev = current
, current = next
).head
to prev
(new head is the last node).To read more about Reversal Operation in Linked List Refer, Reverse a Linked List
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4