Page 49 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 49

Advanced Data Structure and Algorithms




                    Notes                     if(temp -> link == NULL)
                                              {
                                                       printf(“Error\n”);
                                              }
                                                 exit(0);
                                                 temp = temp-> link;
                                                 temp-> data = n;
                                                 temp-> link = p;
                                              }
                                              return (p);
                                        }
                                        void printlist ( struct node *p )
                                        {
                                           struct node *temp;
                                           temp = p;
                                           printf(“The data values in the list are\n”);
                                           if(p!= NULL)
                                           {
                                           do
                                           {
                                                     printf(%d\t”,temp->data);
                                                     temp=temp->link;
                                           } while (temp!= p)
                                        }
                                        else
                                           printf(“The list is empty\n”);
                                        }
                                        void main()
                                        {
                                           int n;
                                           int x;
                                           struct node *start = NULL ;
                                           printf(“Enter the nodes to be created \n”);
                                           scanf(“%d”,&n);
                                           while ( n- > 0 )
                                           {
                                                   printf( “Enter the data values to be placed in a
                                     node\n”);
                                              scanf(“%d”,&x);
                                              start = insert ( start, x );
                                           }
                                           printf(“The created list is\n”);
                                           printlist ( start );
                                        }




          44                               LOVELY PROFESSIONAL UNIVERSITY
   44   45   46   47   48   49   50   51   52   53   54