-->

Tuesday, February 18, 2014

Circular Linked List for Data Structure in C Programming

Circular Linked List for Data Structure in C Programming

Circular Linked List

A little variation applied to linear linked list gives another type of linked list called as circular linked list. You might have observed in the linear linked list that the last node always points to the invalid address such as NULL address. Practically speaking the memory is wasted. Instead of NULL address if we think to keep the valid address in that field such as the address of the first node available in external pointer ROOT, then the linear linked list becomes circular linked list. As the last point in the circular linked list always points to the first node this type of linked list carries the name circular. The implementation is straightforward.
Whenever you create the circular linked list always assign the pointer field of the newly added node with the first node address given by ROOT(external pointer).

Algorithm to create a circular linked list:
         CREATECLL
         ROOT<--NULL;       CHOICE<--‘Y’
         Repeat While CHOICE=’Y’
            If AVAIL=NULL Then:
               Write: ’Memory Allocation Error’
               Exit.
            Else:
              NEW<--AVAIL
              NEW-->INFO<--Information
              AVAIL<--AVAIL-->LINK
           [End of if]
           If ROOT=NULL Then:
             ROOT<--NEW;   TEMP<--NEW
           Else:
             TEMP-->LINK<--NEW;    TEMP<--NEW
           [End of If]
           NEW-->LINK<--ROOT
           Write: ‘Do you want to add another node?(Y/N)’
           Read: CHOICE
          [End of while]
        Exit.

Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved