10. Python program to insert a new node at the middle of the Circular Linked ListIn this program, we create a circular linked list and insert a new node in the middle of the list. If the list is empty, both head and tail will point to the new node. If the list is not empty, then we will calculate the size of the list and divide it by 2 to get the midpoint of the list where the new node needs to be inserted. After inserting the new node in the middle of the list. Consider the above diagram; the new node needs to be added to the middle of the list. First, we calculate the size which in this case is 4. So, to get the midpoint, we divide it by 2 and store it in a variable count. We will define two nodes current, and temp such that temp will point to head, and current will point to the node previous to temp. We iterate through the list till midpoint is reached by incrementing temp to temp.next then, insert the new node in between current and temp. Current'next node will be new, and the new's next node will be temp. ALGORITHM:
a. display() will show all the nodes present in the list.
PROGRAM:Output: Original list: 1 2 3 4 Updated List: 1 2 5 3 4 Updated List: 1 2 5 6 3 4
Next TopicPython Programs
