We have discussed different methods of linked list insertion. How to recursively create a linked list?
Recursively inserting at the end:
To create a Linked list using recursion follow these steps. Below steps insert a new node recursively at the end of linked list.
Recursively traversing the list:
The idea is simple, we print current node and recur for remaining list.
Below is complete program to demonstrate working of insert and traverse a linked list.
// Recursive C# program to recursively insert
// a node and recursively print the list.
public class Node
public int data;
public Node next;
// Allocates a new node with given data
static Node newNode(int data)
Node new_node = new Node();
new_node.data = data;
new_node.next = null;
// Function to insert a new node at the
// end of linked list using recursion.
static Node insertEnd(Node head, int data)
// If linked list is empty, create a
// new node (Assuming newNode() allocates
// a new node with given data)
if (head == null)
// If we have not reached end, keep traversing
head.next = insertEnd(head.next, data);
static void traverse(Node head)
if (head == null)
// If head is not null, print current node
// and recur for remaining list
Console.Write(head.data + ” “);
// Driver code
public static void Main(String args)
Node head = null;
head = insertEnd(head, 6);
head = insertEnd(head, 8);
head = insertEnd(head, 10);
head = insertEnd(head, 12);
head = insertEnd(head, 14);
// This code is contributed by 29AjayKumar
6 8 10 12 14
This article is contributed by AMIT KUMAR. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Insertion in Unrolled Linked List
- Insertion Sort for Singly Linked List
- Doubly Linked List | Set 1 (Introduction and Insertion)
- Circular Singly Linked List | Insertion
- Doubly Circular Linked List | Set 1 (Introduction and Insertion)
- Insertion in a sorted circular linked list when a random pointer is given
- Insertion at Specific Position in a Circular Doubly Linked List
- Recursive Approach to find nth node from the end in the linked list
- Modify contents of Linked List - Recursive approach
- Check if linked list is sorted (Iterative and Recursive)
- Find Length of a Linked List (Iterative and Recursive)
- Search an element in a Linked List (Iterative and Recursive)
- Recursive function to delete k-th node from linked list
- Recursive approach for alternating split of Linked List
- Circular Linked List | Set 2 (Traversal)