EmbLogic's Blog

function to detect comon node in two linked lists and correct them.

int fix_cnode(struct node **start, struct node **start1)
{
struct node *temp,**ma,*temp1;
int count = 0,i,flag =1;
temp = *start;
ma = calloc(sizeof(struct node *),20);
while(1)
{
flag = 1;
if(!(temp->next))
{
printf(“there is no loop\n”);
goto o;
}
for(i=0; i<count; i++)
{
if(temp->next == *(ma+i))
flag = 0;
break;

}
if(flag == 1)
{
*(ma+(count)) = temp;
printf(“%d\n”,*(ma+count));
count++;
}
printf(”                            count = %d\n”,count);
temp = temp->next;

}
o:        temp = *start1;
for(i = 0; i<count; i++)
{
if(temp->next == *(ma+i))
break;
temp = temp->next;
}
printf(“common node is detected at %d\n”,temp->next->info);
temp ->next= NULL;
return 0;

}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>