7/15/21

Circular linked list

 

UNIT: - 5 (Part - 2)

    Linked List: -

     Circular linked lists,

     Doubly linked lists

 

Circular Linked List: -

1.     A linked list in which the last node points back to the first node instead of containing NULL pointer is termed as a circular linked list.

 

        

 

Circular linked list have certain advantages over singly lined list.

1.   The first of these is concerned with the accessibility of a node is accessible from a given node.

2.   Deletion of node from a circular linked list is easy.

3.   Operation such as concatenation and splitting the list are more efficient on circular lists.

4.    A circular linked list would more likely to be used in an application which requires round-robbin scheduling or processing.

5.   However there us a disadvantage of circular linked is, if processing without care it is possible to get into infinite loop.

Operation of Circular linked list: -

1. Insertion operation: -

Inserting logic varies depending on where in the list element is going to be inserted, first, middle, or at the end. In all situations it is as simple as making the pointer point to different nodes and hence insertion at any place is must faster.

1. Inserting at beginning: -

Step 1: -  Create a new node using malloc().

Step 2: -  Make the next field of new node point to the node pointed by head.

Step 3: -  Make the head pointer point to new node.

Step 4: -  Make the last node next pointing to the node which is pointed by head. 

 

     

 

1. Inserting at middle: -

Step 1: -       Create a node using malloc() function.

Step 2: -       Point the new node to its successor by making the next field of new node point to the next of predecessor node.

Step 3: -       Make the predecessor node point to new node.

 

 

       

  

1. INSET AT END (After last node): -

Insert in end involves inserting any element at the end of the list.

Step 1: -       Create a node using malloc() function.

Step 2: -       Make the next field of new node point to NULL.

Step 3: -       Make the predecessor node point to new node.

            

 

             

 

 

    Deletion operation: -

Deletion logic varies depending on from where the node is getting deleted from beginning, middle or from the end.     

        1. Delete from beginning (First node): -

 

Step 1: -        Store the node to be deleted in a temporary pointer.

Step 2: -        Make head point to the first nodes successor in the list.

Step 3: -        Make the last node next pointing to the node pointed by head

Step 4: -        Delete the node pointed by temporary pointer. 

 

                                   

 

            

 

 

        2. Delete from middle: -

Step 1: -        Store the node to be deleted in a temporary pointer.

Step 2: -        Make the predecessor node point to the successor of the node being deleted.

Step 3: -        Delete the node pointed by the temporary pointer.

 

               

 

 

        3. Delete last node: -

Step 1: -        Store the node to be deleted in a temporary pointer.

Step 2: -        Move the head  pointer to the predecessor next field of last node.

Step 3: -        Delete the node pointed by temporary pointer.

        

 

 

 NEXT TOPIC DOUBLY LINKED LIST WILL UPLOADED SOON...

PLEASE COMMENT IF YOU LIKE THIS NOTES

THANK YOU

 

 

 

 

 

 

 

 

 

 

4 comments:

Please do not enter any spam link in the comment box and use English and Hindi language for comment.

Latest Update

Key Components of XML

Popular Posts