Javatpoint Logo
Javatpoint Logo

Traversing in doubly linked list

Traversing is the most common operation in case of each data structure. For this purpose, copy the head pointer in any of the temporary pointer ptr.

then, traverse through the list by using while loop. Keep shifting value of pointer variable ptr until we find the last node. The last node contains null in its next part.

Although, traversing means visiting each node of the list once to perform some specific operation. Here, we are printing the data associated with each node of the list.

Algorithm

  • Step 1: IF HEAD == NULL
  •   WRITE "UNDERFLOW"
     GOTO STEP 6
     [END OF IF]

  • Step 2: Set PTR = HEAD
  • Step 3: Repeat step 4 and 5 while PTR != NULL
  • Step 4: Write PTR → data
  • Step 5: PTR = PTR → next
  • Step 6: 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
23

Press 0 to insert more ?

Node Inserted
1.Append List
2.Traverse
3.Exit
4.Enter your choice?1

Enter the item
90

Press 0 to insert more ?

Node Inserted
1.Append List
2.Traverse
3.Exit
4.Enter your choice?2
90
23
23

Next TopicDoubly Linked List




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA