Page 132 - DCAP201_FUNDAMENTALS_OF_DATA_STRUCTURES
P. 132

Unit 8: Operations on Linked List




                                                                                                Notes
                           Figure 8.29: Update the Next Pointer of Previous Node











          Source: http://www.csie.ntu.edu.tw/~hsinmu/courses/lib/exe/fetch.php?media=dsa_12spring:
          dsame_chap3.pdf
          void InsertAtEndInCLL (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;
          newNode—>next = newNode;
          if(*head == NULL){
          *head = newNode;
          else
          newNode—>next = *head;
          current—>next = newNode;
          }
          }

          Inserting a Node at Front of a Circular Linked List

          The only difference between inserting a node at the beginning and at the ending is that, after
          inserting the new node we just need to update the pointer. Below are the steps for doing the
          same.


                 Example: The example given below shows the steps for Inserting a Node at Front of a
          Circular Linked List.

               Create a new node and initially keep its next pointer points to itself.
                                    Figure 8.30: Create a New Node











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




                                           LOVELY PROFESSIONAL UNIVERSITY                                   125
   127   128   129   130   131   132   133   134   135   136   137