Friday, September 28, 2012

How to compare two linked lists? Write a C program to compare two linked lists.

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); }

No comments: