Home » Traversing in Circular Singly Linked List

Traversing in Circular Singly Linked List

by Online Tutorials Library

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
  • WRITE “EMPTY LIST”
    GOTO STEP 8
    END OF IF

  • STEP 4: REPEAT STEP 5 AND 6 UNTIL PTR → NEXT != HEAD
  • STEP 5: PRINT PTR → DATA
  • STEP 6: PTR = PTR → NEXT
  • [END OF LOOP]

  • STEP 7: PRINT PTR→ DATA
  • STEP 8: EXIT

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

You may also like