Page 53 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 53

Advanced Data Structure and Algorithms




                    Notes






                                                      p







                                                      q

                                                 The given lists





                                                     r




                                                 The resultant list


                                   You can merge two lists into one list. The following program merges two circular lists.



                                   Lab Exercise    Program:

                                     # include <stdio.h>
                                     # include <stdlib.h>
                                        struct node
                                        {
                                        int data;
                                        struct node *link;
                                        };
                                        struct node *insert(struct node *p, int n)
                                        {
                                        struct node *temp;
                                        /* if the existing list is empty then insert a new node as the
                                     starting node */
                                        if(p==NULL)
                                        {
                                           p=(struct node *)malloc(sizeof(struct node)); /* creates new node
                                     data value passes
                                        as parameter */
                                             if(p==NULL)



          48                               LOVELY PROFESSIONAL UNIVERSITY
   48   49   50   51   52   53   54   55   56   57   58