Given a number x, write a program to delete all occurrences of x from a linked list
in one iteration. That is, you can not scan the list more than once.
It only deletes the first occurrence of X, can someone help fixing it please?
I already told you how to fix it. Even so, you should try by yourself.
That you still have the return in there shows that you have no idea what it actually does. The obvious thing to do is to look that up. Why haven't you done that long ago?
I explained that as well. Step through your code line by line and reproduce on paper what it does when feeding your test list to the function. Then you'll see why it's wrong.
I don't need to run it to see that it's wrong and why it's wrong.
But you should already know that yourself, after all you don't get the desired results.
Here's two relevant lists you can use for your pen and paper experiment: 1 2 2 3
And for good measure: 1 2 2 3 2