Page 133 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 133

Fundamentals of Data Structures




                    Notes              Update the next pointer of new node with head node and also traverse the list until the tail.
                                       That means in circular list we should stop at the node which is its previous node in the list.

                                                          Figure 8.31: Update the Next Pointer













                                   Source: http://www.csie.ntu.edu.tw/~hsinmu/courses/lib/exe/fetch.php?media=dsa_12spring:
                                   dsame_chap3.pdf
                                       Update the previous node of head in the list to point to new node.

                                                          Figure 8.32: Update the Previous Node










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

                                                         Figure 8.33: Making New Node as Head













                                   Source: http://www.csie.ntu.edu.tw/~hsinmu/courses/lib/exe/fetch.php?media=dsa_12spring:
                                   dsame_chap3.pdf
                                   void InsertAtBeginInCLL (struct CLLNode **head, int data ) {
                                   struct CLLNode *current = *head;
                                   struct CLLNode * newNode = (struct node*) (malloc(sizeof(struct
                                   CLLNode))); if(!newNode) {
                                   printf(“Memory Error”); return;
                                   }
                                   newNode—>data = data;
                                   while (current—>next != *head)
                                   current = current—>next;




          126                               LOVELY PROFESSIONAL UNIVERSITY
   128   129   130   131   132   133   134   135   136   137   138