Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

List->Dynamic List->Traversal

We have seen the static list traversal and we mean the same here. Here, we will take an auxiliary pointer, 'current', which will initially point to the beginning of the list and will be moved to point to every other node in the list. Let's see the algo. ....

Algorithm:-
Step-1: Initialize the 'Current' pointer with the beginning of the list
Step-2: Print the value for the 'Current' node
Step-3: Make it point to the next node in the list if its there and go to step-2; otherwise stop

C implementation:-
struct NODE
{
int nodevalue;
struct NODE *next;
}
struct NODE *list;

main()
{
...
...
LLtraversal ( list ); /*step-1 of the algo.*/
}

LLtraversal(struct NODE *current)
{
while(current->next != NULL)  /*step-3 of the algo.*/
 {
 printf("%d ->",current->nodevalue); /*step-2 of the algo.*/
 current = current->next;    /*step-3 of the algo.*/
 };
printf("%d", current->nodevalue);   /*find out the reason behind this*/
}

Note:-For traversal I have assumed that the list already exists and the list pointer, "list", is pointing to the beginning of the list.

Related Operations:
Concept
Addition and Deletion of
a node
Traversing of list
Searching for a particular Key
Sorting of list 

Index || Doubts / Clarifications || Related Topics || Web Links