Reversing the ordered Singly Linked List for Data Structure in'C'

Special Operation on linked lists:

Reversing the ordered Singly Linked List:
              In order to reverse the ordered singly linked list, the root must point to the last node of the list. The first node’s address must be copied to the link of second node. Similarly the address of each node is copied in the link of the next node. It works like exchanging the links of each node with the address of the previous node. The algorithm is simple and self-explanatory.
The same is given as follows:

REVERSELL (ROOT)
FIRST<--ROOT [To store the first node’s address]
PPTR<--ROOT        [To store the address in link]
NPTR<--ROOT-->LINK [To store address of previous node]
Repeat While NPTR< >NULL
  ROOT<--NPTR
  NPTR<--NPTR-->LINK
  ROOT-->LINK<--PPTR
  PPTR<--ROOT
[End of while]
FIRST-->LINK<--NULL [To make first node as last]
Return ROOT
Exit.

Posted on by Jackrin Reacher | No comments

0 comments:

Post a Comment