Here is my improved code based on Steve's comment (with node feedback):
while (hare != back)
{
tortoise = tortoise.next();
hare = hare.next().next();
if (hare == tortoise) throw new AssertionError("cyclic linkage");
}
I do not see a place where this will violate the client code, and my unit tests confirm this. Fine:)
source
share