Traverse Reverse and Circular Functions

traverse,reverse and circular link lists

Traverse:

Define:

Traverse is the shifting of a node from one node to next to next and so on.Mean a node is at the start has the data of first node and pointer of second node then after first traversing it has the  data of the second node and the pointer of the third node then in the next step it has the data of the third node and the pointer of the fourth node.In this way the method is going on and on till the last node data it has and then as the last node has null value in the pointer so the traversing end at that point.

how to traverse a link list

Usage:

Traversing is mostly used in the searching ,removing and inserting any element in the list purposes.
Every time when traversing is done there would make a new temporary pointer which taken the value or data of the first then after every step of traversing it take the data of the next node and shift toward the next node every time and at the last it traverse the whole list and reach at the last pointer  after that their would be a null and the traversing stop at that point.


Reverse:

Define:

Reverse mean the last node of the list will become the first node and the second next will become the second first and in the same and continuous function works for all the nodes until the first node become the last node.
how to make reverse link list

Usage:

Reversing is mostly done for shifting the list ways in the stack and queue.
Firstly the last pointer value put in the new temporary pointer and then start traversing first time when the traversing temp pointer reach at the last pointer then the last pointer become the first and the second next become the last pointer and for the next all steps when temp pointer reach at last the second last become the last and the already last pointer attach with the new list which start from the first and in this way the traversing is done and reversing also done when the first node will become the last node at the end.


Circular:

Define:

Circular mean making the list in a circle in this the last node attached with the first node and every time when the temporary pointer reach at the last node then it will again reach at the first node because both are attached with each other.
circular link list and types

Usage:

Circular list is used for running something in the loop.
In this there must be used only one pointer either it will be the first or it will be the last and if there is only one node then its next has its own address and the last also  has the own address but if there are more then one nodes in a list then every last node has the address of the first in its next and first have the address of every last node in its previous in this way the circular list work.

Post a Comment

0 Comments