data structure

Im using c++ compiler but with .c extension. so my codes in c compile successfully. the problem is when i deleted a node in a list (im using link list) the node that i deleted is not gone but replaced with special characters. what is the problem? here is my code

char delet(ListNodePtr *sPtr, char value)
{
ListNodePtr previousPtr, currentPtr, tempPtr;

if(value==(*sPtr)->data)
{
tempPtr=*sPtr;
*sPtr=(*sPtr)->nextPtr;
free(tempPtr);
return value;
}
else
{
previousPtr=*sPtr;
currentPtr=(*sPtr)->nextPtr;

while(currentPtr!=NULL && currentPtr->data!=value)
{
previousPtr=currentPtr;
currentPtr=currentPtr->nextPtr;
}

if(currentPtr!=NULL)
{
tempPtr=currentPtr;
previousPtr->nextPtr=currentPtr;
free(tempPtr);
return value;
}
}
return '\0';
}

whats wrong?
What C++ / C compiler do you use and on what OS?
1
2
3
4
5
6
7
       if(currentPtr!=NULL)
        {
            tempPtr=currentPtr;
            previousPtr->nextPtr=currentPtr;
            free(tempPtr);
            return value;
        }


should be:

1
2
3
4
5
6
        if(currentPtr!=NULL)
        {
            previousPtr->nextPtr = currentPtr->nextPtr ;
            free(currentPtr) ;
            return value ;
        }
@cire

it runs succesfully now! thank you so much!!! hehe
Topic archived. No new replies allowed.