Wednesday 28 June 2017

Compare cnd copye the Linked List

int compare_linked_lists(struct node *q, struct node *r)
{
      static int flag;

      if((q==NULL ) && (r==NULL))
      {
           flag=1;
       }
      else
       {
           if(q==NULL || r==NULL)
            {
                flag=0;
             }
           if(q->data!=r->data)
             {
                  flag=0;
              }
            else
              {
                  compare_linked_lists(q->link,r->link);
               }
    }
    return(flag);
}


copy_linked_lists(struct node *q, struct node **s)
{
      if(q!=NULL)
      {
          *s=malloc(sizeof(struct node));
         (*s)->data=q->data;
         (*s)->link=NULL;
         copy_linked_list(q->link, &((*s)->link));
       }
}

 

No comments:

Post a Comment