CJCoding With Joseph
15free / daySign inCreate account

Delete a Linked List Node by Value

Read an integer n, then n values, 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 and free() that one node — and print the list again. Between the two lists print one status line: Removed TARGET if a node was deleted, or Not found TARGET if 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 and NULL after 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
Topics:
Pointers
📥 Auto-Input:
4\n4 8 15 8\n8\n
This input is automatically fed to your program's stdin
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.