← Back to Pointers
Question 473
Delete a Linked List Node by Value
Delete a Linked List Node by Value
Read an integern, thennvalues, and build a singly linked list holding them in the order they were read. Then read one more integer: the target. Print the list, delete the FIRST node whose value equals the target — unlink it andfree()that one node — and print the list again. Between the two lists print one status line:Removed TARGETif a node was deleted, orNot found TARGETif no node held that value. For the input: 4 4 8 15 8 8 the program prints exactly the output shown in Expected Output. Only the first match goes. Deleting the head must also work. List format: the label, a colon, then for EVERY node a space, the value, a space and->, and a space andNULLafter the last node. Free the memory you allocate before the program ends — this question checks for memory leaks.
Expected Output:
Before: 4 -> 8 -> 15 -> 8 -> NULL Removed 8 After: 4 -> 15 -> 8 -> NULL
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Pointers
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (p, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.