hello everyone I'm trying to find this algorithm on c++ in net but can't, I found this one
// Best solution
function boolean hasLoop(Node startNode){
Node slowNode = Node fastNode1 = Node fastNode2 = startNode;
while (slowNode && fastNode1 = fastNode2.next() && fastNode2 = fastNode1.next()){
if (slowNode == fastNode1 || slowNode == fastNode2) return true;
slowNode = slowNode.next();
}
return false;
}
but doesn't seem to be right, or am I wrong? how can I actually prove that my hare will meet turtose at the end? tranks in advance for any explanation how exactly does it work and proof
EDITED
about this solution, I found that in regular algorithm they use only one fast iterator but here they use two, why?