Search This Blog

Sunday, September 21, 2014

WAP to find common data position in two different given Singly Linked lists.

1:  void find_common_nodes_position(list_t *list1,list_t *list2)  
2:  {  
3:    int pos1=0,pos2=0;  
4:    list_t *temp1 = NULL;  
5:    list_t *temp2 = NULL;  
6:    for(pos1=1,temp1=list1;temp1;temp1=temp1->next,pos1++)  
7:    {  
8:      for(pos2=1,temp2 = list2;temp2;temp2 = temp2->next,pos2++)  
9:      {  
10:        if ( temp1->data == temp2->data)  
11:        {  
12:          printf("Data %d common at %d in list1 and %d at list2\n",  
13:                          temp1->data,pos1,pos2);  
14:        }  
15:      }  
16:    }  
17:    return;  
18:  }  

No comments:

Post a Comment