VOOZH about

URL: https://www.geeksforgeeks.org/dsa/insert-a-node-at-the-end-of-doubly-linked-list/

⇱ Insert a Node at the end of Doubly Linked List - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Insert a Node at the end of Doubly Linked List

Last Updated : 12 Dec, 2025

Given a Doubly Linked List, insert a new node at the end of the linked list.

Examples:

Input: Linked List = 1 <-> 2 <-> 3, NewNode = 4
Output: 1 <-> 2 <-> 3 <-> 4

Input: Linked List = NULL, NewNode = 1
Output: 1

Approach:

Inserting at the end involves traversing the entire list until we reach the last node. We then set the last node’s next reference to point to the new node and new node's previous reference to point to the last node. Thus, making the new node the last element in the list.

👁 Insertion-at-the-End-in-Doubly-Linked-List
Insert node 4 at the end of Doubly Linked List

Steps to insert a new node at the end:

  • If the linked list is empty, we set the new node as the head of linked list and return it as the new head of the linked list.
  • Otherwise, traverse the entire list until we reach the last node, say curr.
  • Then, set the last node’s next to new node and new node’s prev to last node, making the new node the last element in the list.

Output
1 <-> 2 <-> 3 <-> 4

Time Complexity: O(n), where n is the number of nodes in the linked list.
Auxiliary Space: O(1)

Comment
Article Tags: