Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a function to insert a given item before a specified node known as key nod

ID: 3630782 • Letter: W

Question

Write a function to insert a given item before a specified node known as key node

Explanation / Answer

node *insert(node *head) { node *find(node *p, int a); node *new; /* pointer to new node */ node *n1; /* pointer to node preceding key node */ int key; int x; /* new item (number) to be inserted */ printf(“Value of new item?”); scanf(“%d”, &x); printf(“Value of key item ? (type –999 if last) “); scanf(“%d”, &key); if(head->number == key) /* new node is first */ { new = (node *)malloc(size of(node)); new ->number = x; new->next = head; head = new; } else /* find key node and insert new node */ { /* before the key node */ n1 = find(head, key); /* find key node */ if(n1 == NULL) printf(“ key is not found ”); else /* insert new node */ { new = (node *)malloc(sizeof(node)); new->number = x; new->next = n1->next; n1->next = new; } } return(head); } node *find(node *lists, int key) { if(list->next->number == key) /* key found */ return(list); else if(list->next->next == NULL) /* end */ return(NULL); else find(list->next, key); }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote