Comparing a pointer with integer

Your while loop test is wrong. It should be testing for a null pointer to a node, like this:

while(temp1 != NULL)  // <-- this line was wrong
{
    temp2=temp1;
    if(value<=temp1->data)
    {
        temp1=temp1->lchild;
    }
    else
    {
        temp1=temp1->rchild;
    }
}

Leave a Comment