Search

Monday, February 24, 2014
0 comments

Understanding creation of doubly linked list for Data Structrue in 'C'

9:35 PMMonday, February 24, 2014
Understanding creation of doubly linked list:
                                                                                                  
One node with information ‘6’ is added to the doubly linked list. Then the list become,
                                                                                                                                                                                                                                                         



Another node with information ‘16’ is added to the circular linked list. Then the list become,


Similarly when two more nodes are added with information ‘1’ and ’61’, the list become,



Traversing the Doubly Linked List

       Set a pointer variable PTR with ROOT. Process PTR-->INFO and update PTR by LINK of PTR i.e. PTR<--PTR-->LINK. Repeat till the PTR is NULL. The algorithm is as follows:

      TRAVERSDLL (ROOT)
      PTR<--ROOT
      Repeat While PTR< >NULL
      Apply process to PTR-->INFO
      PTR<--PTR-->LINK
      [End of while]
      Exit

Algorithm to print the contents of a linked list:

      TRAVERSEDLL (ROOT)
      PTR<--ROOT
      Repeat While PTR< >NULL
      Write: PTR-->INFO;  PTR<--PTR-->LINK
      [End of while]
      Exit.

        From the just created doubly list in the example shown it is possible to traverse the doubly linked list in reverse order starting from the last node. Address of the last node is available in external pointer TEMP. Set a pointer variable PTR with TEMP. Process PTR-->INFO and update PTR by storing the address of previous node given by the pointer part PREV of PTR i.e. PTR<--PTR-->PREV. Repeat till the PTR is NULL.
The algorithm is as follows:

       TRAVERSEDLLRO
       PTR<--TEMP
       Repeat While PTR< >NULL
       Apply process to PTR-->INFO; PTR<--PTR-->PREV
       [End of while]
       Exit.
  Rests of the operations are similar to singly linked list and are left out as exercises.

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top