Write a function to delete a specified node. Solution node *delete(node *head) {
ID: 3630783 • Letter: W
Question
Write a function to delete a specified node.Explanation / Answer
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(“ 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(“ key not found ”); 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 */
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.