Page 41 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 41

Advanced Data Structure and Algorithms




                    Notes                        exit(0)

                                           }
                                           temp1 -> data = value ;
                                           temp1 -> link = temp -> link;
                                           temp -> link = temp1;
                                        }
                                        return (p);
                                        }
                                        void printlist ( struct node *p )
                                        {
                                           printf(“The data values in the list are\n”);
                                           while (p!= NULL)
                                           {
                                              printf(“%d\t”,p-> data);
                                              p = p-> link;
                                           }
                                        }
                                        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 list before deletion is\n”);
                                           printlist ( start );
                                           printf(“ \n Enter the node no after which the insertion is to be
                                     done\n”);
                                           scanf ( “ %d”,&n);
                                           printf(“Enter the value of the node\n”);
                                           scanf(“%d”,&x);
                                           start = newinsert(start,n,x);
                                           printf(“The list after insertion is \n”);
                                           printlist(start);
                                        }


          36                               LOVELY PROFESSIONAL UNIVERSITY
   36   37   38   39   40   41   42   43   44   45   46