Javatpoint Logo
Javatpoint Logo

Traversing in singly linked list

Traversing is the most common operation that is performed in almost every scenario of singly linked list. Traversing means visiting each node of the list once in order to perform some operation on that. This will be done by using the following statements.

Algorithm

  • STEP 1: SET PTR = HEAD
  • STEP 2: IF PTR = NULL
  •    WRITE "EMPTY LIST"
      GOTO STEP 7
      END OF IF

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

  • STEP 7: 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?1

Enter the item
233

Node inserted

1.Append List
2.Traverse
3.Exit
4.Enter your choice?2
printing values . . . . .

233
23

Next Topic#




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA