Singly Linked List

A Singly Linked List (SLL) is a type of linked list where each node contains a data field and a reference to the next node in the sequence. The last node points to null. It is a dynamic data structure, which means it can grow and shrink during runtime.

Basic Operations on Singly Linked List:

  1. Insertion: Add a node at the beginning, end, or a specific position.
  2. Deletion: Remove a node from the list.
  3. Traversal: Visit all nodes in the list.
  4. Search: Find a node with a specific value.
  5. Reverse: Reverse the order of nodes in the list.

This is the representation of SinglyLinkedList.

A linked list is composed of nodes. Each node contains:

  • Data: The value stored in the node.
  • Next Pointer: A reference to the next node in the list.

Insertion: Add a node at the beginning, end, or a specific position.

First we write the Pseudocode for Singly Linked List Operations

  • Add a node at the beginning. 
  • Adding a node at the end.
  • Adding a node at a specific position.

Node Structure

Define Node Structure:
    Node:
        - data: Integer
        - next: Node
Adding a node at the end

We add a node at the End of the Singly Linked List.

Pseudocode

Add a node at the beginning

We add a node at the begining of the Singly Linked List.

Pseudocode

Adding a node at a specific position

We add a node at a specific position of the Singly Linked List.

Pseudocode

Code for Insertions In Singly Linked List

Code for Insertions In Singly Linked List

  • Add a node at the beginning. 
  • Adding a node at the end.
  • Adding a node at a specific position.
Insertions Operations In Singly Linked List
ProgLangCode

Code Output
24->4->14->12->5->null