Logic for the given procedure is 1st node of circular linked list.
That is not sure, because any node can be the head node. After all, If a middle node is head node, then again its a circular linked list. In memory, a $CLL$ is stored like a circular queue.
- Let the $CLL$ with head node as a node having element $5$ be :
- Add a New node $N$ as follows in $O(1)$ time :
- Swap the Data $N$ and $5$ in O(1) time as :
- Now, again make Node having $5$ as head node in O(1) time as :
- Now, the new CLL is as follows :
- All the steps are in total done in $O(1)$ time.