head = tail = new Link();
Here you assign head and tail to point to the same link object. Since you never reassign either of them, that means that any time you change any property of head (e.g. head.next = foo
), the same change is applied to tail.
Meaning head and tail will always have the same element, the predecessor and the same successor. Obviously this does not lead to the intended results.