There are a few mistakes in your code. The most obvious is the return of "head". If head.data == value then you should not return head but the first available node with a different value. If I recall correctly that would be the return value of removeAll(head.next, value).
Let's consider the different cases:
1) head == null. There is nothing to check so return head (or null, but these are the same).
2) head.data == value and head.next == null. head should be removed, but it's the only node. The only thing to return is null.
3) head.data == value and head.next != null. head should be removed, the remainder should be checked. I'm sure you'll be able to figure out what to return.
4) head.data != value and head.next == null. head should not be removed and it's the only node. The only thing to return is head itself.
5) head.data != value and head.next != null. head should not be removed, but its next node may be. I'm sure you'll be able to figure out what to return.
In code (with gaps):
You can shorten this code but this is how it basically works.
What's your new code? Something tells me that the problem is the line "ptr.data = ptr.next.data;". That copies the data of the next node to this node but doesn't remove either node.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.