News for hackers. Stuff that matters.
Re:Ask HN: Favorite pointer tricks in C? by Jach on Saturday November 20, 2010 @06:04PM (#1925645)
I remembered another one, the teleporting turtle algorithm. http://www.penzba.co.uk/Writings/TheTeleportingTurtle.html It's a neat way to determine if there are loops in a linked list (among many other uses).

We start with the turtle and rabbit pointing to the head, and then on each clock tick we advance the rabbit by one step. After a while, assuming we've neither found the end of the list nor caught the turtle, we teleport the turtle to the rabbit's position, double the length of time we're willing to wait, then go again.

There are no comments on this comment yet.