We have discussed Circular Linked List Introduction and Applications,in the previous post on Circular Linked List. In this post, traversal operation is discussed.
In a conventional linked list, we traverse the list from the head node and stop the traversal when we reach NULL. In a circular linked list, we stop traversal when we reach the first node again. Following is C code for linked list traversal.
/* Function to traverse a given Circular linked list and print nodes */
structnode *temp = first;
// If linked list is not empty
if(first != NULL)
// Keep printing nodes till we reach the first node again
printf("%d ", temp->data);
temp = temp->next;
while(temp != first);
Complete C program to demonstrate traversal. Following is complete C program to demonstrate traversal of circular linked list.
/* structure for a node */
/* Function to insert a node at the begining of a Circular