Why implementation A is wrong?


#1


#2

Implementation A is not wrong if you pass head of the linked list as argument. But instead if you pass any other node then it will work but change the meaning of insertion,i.e. insertion at beginning.

say you have a linked list 1->2->3

Now say head points to 1.
If you pass head as your argument in function call, then it won’t be wrong.
Like this, insert(head,5);

But if you pass anything other than the head node, then it will work but insertion will be done somewhere else.
like this, insert(head.next,5);

In the above case the implementation will fail.