Java Program to Insert a New Node at the Middle of the Circular Linked List
Given a Circular Linked List, the task is to add a New Node at the Middle of the List. Let’s consider the following Circular Linked List:
- Create a new node (New_node).
- Check for an empty list. If the list is empty then insert the node as head.
- For non-empty list, calculate the length of the list.
- Create variable mid and store middle length in it.
- Create two nodes Temporary and Current.
- Now traverse the list till Temporary reaches the midpoint of the list using the mid variable.
- Insert the New_node after the Current.
- Make Current.next point to New node and New_node.next to Temporary.
- Node is inserted.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
Original List --> 10 20 30 40 List after Inserting --> 10 20 60 30 40