0
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 ?

Thejas
  • 59
  • 5
  • This looks like C, not Javascript. Why do you have the jQuery tag? – Barmar Oct 16 '14 at 16:01
  • im really sorry about that . My bad . – Thejas Oct 16 '14 at 16:04
  • I don't see values for n, block, closed_area. So the if statement can't be understood. Also post code or link to library doc for fastintersect, and I'll be able to understand what your code does – Alex Cornford Oct 16 '14 at 16:18
  • Hi Alex ! I have edited it to include the fastintersect() function – Thejas Oct 16 '14 at 16:32
  • 1
    The routine looks like it should function. I don't have doc for the Append, Delete etc. I don't fully understand the if statement - it's accuracy is critical for your results – Alex Cornford Oct 16 '14 at 17:23

0 Answers0