Page 56 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 56

Unit 2: Linked Lists





                      printlist ( start1 );                                                     Notes
                      /* this will create the second circular list nodes*/
                      printf(“Enter the number of nodes in the second list \n”);
                      scanf(“%d”,&n);
                      while ( n-- > 0 )
                      {
                   printf( “Enter the data value to be placed in a node\n”);
                          scanf(“%d”,&x);
                          start2 = insert ( start2, x );
                      }
                      printf(“The second list is:\n”);
                      printlist ( start2 );
                      start3 = merge(start1,start2);
                      printf(“The resultant list is:\n”);
                      printlist(start3);
                }




              Task    Write a program to reverse a linked list


          2.12 Application of Linked List

          Polynomials in general are represented by the following equation:
                         f(x) = c x  + c  – 1x ei – 1  +....+c x
                               i ei  i         1 e1
          where C  are non zero coefficients of variable x and ei are exponents such that

                 i
                          ei >  ei – 1 > ei – 2 >.........> e1 > 0.
                Example:

                                7
                       F1(x) = 3x  – 7x  + 3x  + 1
                                        2
                                    5
                                        2
                                    5
                                8
                       F2(x) = 5x  + 6x  + 4x  +13
          These Polynomials can be added to form another Polynomial
          Let           f3(x) =  f1(x) +f2(x)
                                8
                                    7
                                       5
                                           2
                        f3(x) = 5x  + 3x  – x  + 7x  + 14

          This is achieved by adding coefficients of variables with same exponent value.
          These Polynomials can be maintained using a Linked List. To achieve this each term will be
          represented by a node and each node should consist of three elements namely coeffi cients,
          exponents and a link to the next term (represented by another node).
          Struct poly     Coef.  Exp.      Link
                         {
                            float coef;




                                           LOVELY PROFESSIONAL UNIVERSITY                                    51
   51   52   53   54   55   56   57   58   59   60   61