Help with Lists?, Please :)
Code:
[//* Delete a list element */
void del( ListNodePtr *sPtr)
{
ListNodePtr previousPtr, currentPtr, tempPtr;
char testvalue[30];
printf("Enter the reg of the car you wish to delete:\n");
scanf("%s",&testvalue);
if(testvalue ==(*sPtr)->reg)
{
tempPtr=*sPtr;
*sPtr = (*sPtr)->nextPtr;
free(tempPtr);
}
else
{
previousPtr = *sPtr;
currentPtr = (*sPtr)->nextPtr;
/* if ( value == ( *sPtr )->data ) {
tempPtr = *sPtr;
*sPtr = ( *sPtr )->nextPtr; /* de-thread the node */
/* free( tempPtr ); /* free the de-threaded node */
}
// else {
// previousPtr = *sPtr;
//currentPtr = ( *sPtr )->nextPtr;
while ( currentPtr != NULL) {
previousPtr = currentPtr; /* walk to ... */
currentPtr = currentPtr->nextPtr; /* ... next node */
}
if ( currentPtr != NULL ) {
tempPtr = currentPtr;
previousPtr->nextPtr = currentPtr->nextPtr;
free( tempPtr );
}
}
// return '\0';
Hi I'm having trouble figuring out a delete function for my link list, have several fields in the structure, as I have it now it runs but doesn't delete it. I'm also interested in instering an update function but I'm not quite sure what the coding is like on it, any help would be greatly appreciated.Thanks