struct node
{
int data ;
struct node * link ;
} ;
void delete ( struct node **q, int num )
{
struct node *old, *temp ;
temp = *q ;
while ( temp != NULL )
{
if ( temp -> data == num )
{
/* if node to be deleted is the first node in the linked list */
if ( temp == *q )
*q = temp -> link ;
/* deletes the intermediate nodes in the linked list */
else
old -> link = temp -> link ;
/* free the memory occupied by the node */
free ( temp ) ;
return ;
}
/* traverse the linked list till the last node is reached */
else
{
old = temp ; /* old points to the previous node */
temp = temp -> link ; /* go to the next node */
}
}
printf ( "\nElement %d not found", num ) ;
}