Hi everyone! I have a little problem with the solution of this exercise:
List exercise: Given two lists, A and B, write a function which delete common elements in the list named "B".
Here there is what I written:
Code:
void delete_commons (int m, struct node *B, struct node *A){
int i;
for (i=0;i<m;i++){
if ((B->value)==(A->value)){
struct node *temp;
temp=B;
B= &(*(B->next));
free (temp);
A=&(*A->next);
delete_commons (m-1,B,A);
}
else{
A=&(*A->next);
delete_commons (m-1,B,A);
}
B=&(*(B->next));
}
}
There is a bug, but I can't fix that.
NOTE:
1)Struct node is the structured data formed by the float value and the pointer to another node;
2) "m" is the number of nodes of the list named "B"