Page 135 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 135

Fundamentals of Data Structures




                    Notes              Dispose the tail node.
                                                           Figure 8.36: Dispose the Tail Node













                                   Source: http://www.csie.ntu.edu.tw/~hsinmu/courses/lib/exe/fetch.php?media=dsa_12spring:
                                   dsame_chap3.pdf

                                   The code is given below.
                                   void DeleteLastNodeFromCLL (struct CLLNode **head) {
                                   struct CLLNode *temp = *head;
                                   struct CLLNode *current = *head;
                                   if(*head == NULL) {
                                   printf( “List Empty”);
                                   return;
                                   }
                                   while (current—>next != *head) {
                                   temp = current;
                                   current = current—>next;
                                   }
                                   free(current);
                                   return;
                                   }

                                   Deleting the First Node in a Circular List

                                   The first node can be deleted by simply replacing the next field of tail node with the next field of
                                   the first node.


                                          Example: The example given below shows the steps for deleting the First Node in a
                                   Circular List.
                                       Find the tail node of the linked list by traversing the list. Tail node is the previous node to
                                       the head node which we want to delete.

                                                             Figure 8.37: Find the Tail Node











                                   Source: http://www.csie.ntu.edu.tw/~hsinmu/courses/lib/exe/fetch.php?media=dsa_12spring:
                                   dsame_chap3.pdf



          128                               LOVELY PROFESSIONAL UNIVERSITY
   130   131   132   133   134   135   136   137   138   139   140