struct node* tempA;
struct node* tempB;
n = 501;
m = 501;
tempA = A;
tempB = B;
while ( tempA != NULL && tempB != NULL )
{
if ( tempA->data == tempB->data )
{
int common = tempA->data;
if (fastintersect(common+n,block,closed_area)||fastintersect(common-n,block,closed_area)||(fastintersect(common-1,block,closed_area) && common%n != 1)||(fastintersect(common+1,block,closed_area) && common%n != 0 ))
{
AppendNode(&C,common);
tempA = tempA->next;
tempB = tempB->next;
if( search(A,common) != length(A) )
{
DeleteNode(&A,common);
}
else
{
DeleteEndNode(A);
}
if( search(B,common) != length(B) )
{
DeleteNode(&B,common);
}
else
{
DeleteEndNode(B);
}
}
else
{
tempA = tempA->next ;
tempB = tempB->next ;
}
}
else if ( tempA->data > tempB->data )
tempB = tempB->next;
else
tempA = tempA->next;
}
// The fastintersect function
int fastintersect(int x,int arr[],int sizearr)
{
int found = 0;
int lower = 0;
int upper = sizearr - 1 ;int i=0;
if( (x == arr[lower]) || (x == arr[upper]) )
{
found = 1;
}
else if ( x > arr[lower] && x < arr[upper])
{
while ( lower <= upper )
{
int middle = ( lower + upper ) / 2;
if ( x > arr[middle])
{ lower = middle +1 ;}
else if (x < arr[middle])
{upper = middle - 1;}
else
{ found = 1;break;}
}
}
return found;
}
This is a function to delete the common elements of 2 sorted linked lists A and B . When there are common elements the fastintersect criterion is checked and corresponding elements are deleted and new linked list C is generated whose elements are the ones which satisfy the common elements criteria as well as the fastintersect check .Block is just a matrix which has some values against which the common is checked and if present will return a value 1 else 0. Am I doing the deleting correctly ? Is this a valid code ?