Page 58 - DCAP605_ADVANCED_DATA_STRUCTURE_AND_ALGORITHMS
P. 58

Unit 2: Linked Lists





                         z->exp=p->exp; z1->coef=p->coef;                                       Notes
                         p=p-> link;
                     }
                     if (p->exp<q->exp)
                     {
                         z->exp=q->exp; z1->coef=q->coef;
                     }   q=q->link;
                     if(p-> exp=q->exp)!=0)
                     {
                         z->exp=p->exp;
                         z->coef=p->exp;
                         p=p->link;
                         q=q->link;
                     }
                         z->link = malloc(sizeof(struct poly));
                         z=z1-> link;
                     while (p!=NULL)
                     {
                         z->exp=p->exp;
                         z->coef=p->coef;
                         z->link= malloc(sizeof(struct poly));
                         z=z->link; p=p->link;
                     }
                     while (q!=NULL)
                     {
                         z->exp=q->exp;
                         z->coef=q->coef;
                         z->link=malloe(sizeof(struct poly));
                         z=z->link;
                     }   q=q->link;
                  }
              }
          Cursor Implementation of Linked Lists


          Consider a case where we have two Linked Lists pointed to by two different pointers, say p and
          q respectively, and we want to concatenate 2nd list at the end of the first list. We can do it by



          traversing first list till the end and then store the address of first node in the second list, in the



          link field of last node of first list. Suppose we are traversing first list by pointer temp, then we can
          concatenate the list by the statement (Figure 2.9)
          temp -> link = q;



                                           LOVELY PROFESSIONAL UNIVERSITY                                    53
   53   54   55   56   57   58   59   60   61   62   63