Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Function for deleting an item from linked list

Posted By: Chloe Brown     Category: C Programming     Views: 5632

Write a function to delete a specified node.

Code for Function for deleting an item from linked list in C Programming

node *delete(node *head)
{
    node *find(node *p, int a);
    int  key;    /* item to be deleted */
node *n1; /* pointer to node preceding key node */
node *p; /* temporary pointer */
printf(“\n What is the item (number) to be deleted?”); scanf(“%d”, &key); if(head->number == key) /* first node to be deleted) */
{ p = head->next; /* pointer to 2nd node in list */
free(head); /* release space of key node */
head = p; /* make head to point to 1st node */
} else { n1 = find(head, key); if(n1 == NULL) printf(“\n key not found \n”); else/* delete key node */
{ p = n1->next->next; /* pointer to the node
following the keynode */
free(n1->next); /* free key node */
n1->next = p; /* establish link */
} } return(head); } /* USE FUNCTION find() HERE */
  
Share: 


Didn't find what you were looking for? Find more on Function for deleting an item from linked list Or get search suggestion and latest updates.

Chloe Brown
Chloe Brown author of Function for deleting an item from linked list is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!