TRAVERSING A LINKED LIST: Let List be a linked list in memory stored in linear arrays INFO and LINK with START pointing to the first element and NULL indicating the end of LIST. Suppose we want to traverse LIST in order to process each node exactly once. This section presents an algorithm that does so and then uses the algorithm in some applications.
If You want to learn about the technology, computer science & engineering, web programming, freelancing, earning please click here :CSE SOLVE
Our traversing algorithm uses a pointer variable PTR which points to the node that is currently being processed. Accordingly, LINK[PTR] points to the next node to be processed.
PTR : = LINK[PTR]
Initialize PTR or START. Then process INFO[PTR], the information at the first node.
Update PTR by the assignment PTR : = LINK[PTR]
PTR points at the second node. Then process INFO[PTR], the information at the second node.
Update PTR by the assignment PTR : = LINK[PTR], and
Then process INFO[PTR], the information at the third node.
Continue until PTR = NULL, which signals the end of the list.
0 comments:
Post a Comment