***Welcome to ashrafedu.blogspot.com * * * This website is maintained by ASHRAF***

    Saturday, September 10, 2022

    Circular Linked List

    In Circular linked list the link of the last node is pointed to the first node of the list. Any node in circular linked list can be reached from any other node in the list which is not possible in linear linked list.

    A circular list could be

    Singly circular linked list or

    Doubly circular linked list.

     

    I. Singly Circular Linked List

    In a singly circular list, the pointer head points to the first node of the list. If last node has to be accessed, all the nodes starting from head has to be traversed.

    A better solution to this is set the pointer Head to point to the last node instead of the first node.


    Through Head the last node can be accessed directly, and Head->next, gives us the address of the first node.

    II. Doubly Circular Linked List

    In doubly circular linked list, the last node’s next link is set to the first node of the list and the first node’s previous link is set to the last node of the list.


     

    No comments:

    Post a Comment

    Prim’s algorithm for finding MST (Minimum Spanning Tree)

    Prim's algorithm to find minimum cost spanning tree uses the greedy approach. Prim's algorithm, in contrast with Kruskal's algor...