Page 45 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 45

Advanced Data Structure and Algorithms




                    Notes                }

                                           return (p);
                                        }
                                        void printfor( struct dnode *p )
                                        {
                                           printf(“The data values in the list in the forward order are:\n”);
                                           while (p!= NULL)
                                              {
                                                 printf(“%d\t”,p-> data);
                                                 p = p-> right;
                                              }
                                        }
                                        /* A function to count the number of nodes in a doubly linked list */
                                        int nodecount (struct dnode *p )
                                        {
                                           int count=0;
                                           while (p != NULL)
                                           {
                                              count ++;
                                              p = p->right;
                                           }
                                              return(count);
                                        }
                                        /* a function which inserts a newly created node after the specified
                                     node in a doubly linked list */
                                     struct node * newinsert ( struct dnode *p, int node_no, int value )
                                           {
                                           struct dnode *temp, * temp1;
                                           int i;
                                           if ( node_no <= 0 || node_no > nodecount (p))
                                           {
                                           printf(“Error! the specified node does not exist\n”);
                                           exit(0);
                                           }
                                           if ( node_no == 0)
                                           {
                                           temp = ( struct dnode * )malloc ( sizeof ( struct dnode ));
                                           if ( temp == NULL )
                                           {








          40                               LOVELY PROFESSIONAL UNIVERSITY
   40   41   42   43   44   45   46   47   48   49   50