68
Traversing in Circular Singly linked list
Traversing in circular singly linked list can be done through a loop. Initialize the temporary pointer variable temp to head pointer and run the while loop until the next pointer of temp becomes head. The algorithm and the c function implementing the algorithm is described as follows.
Algorithm
- STEP 1: SET PTR = HEAD
- STEP 2: IF PTR = NULL
- STEP 4: REPEAT STEP 5 AND 6 UNTIL PTR → NEXT != HEAD
- STEP 5: PRINT PTR → DATA
- STEP 6: PTR = PTR → NEXT
- STEP 7: PRINT PTR→ DATA
- STEP 8: EXIT
WRITE “EMPTY LIST”
GOTO STEP 8
END OF IF
[END OF LOOP]
C Function
Output
1.Append List 2.Traverse 3.Exit 4.Enter your choice?1 Enter the item 23 Node Inserted 1.Append List 2.Traverse 3.Exit 4.Enter your choice?2 printing values ... 23
Next TopicDoubly Linked List