Yahoo Interview Question

Write an algorithm to find the middle node of a singly-linked list.

Interview Answer

Anonymous

Nov 10, 2010

Push two pointer along the list, one at one node per iteration and the other at two nodes per iteration. When the second pointer has reached the last node in the list (node->next == NULL) you know the first pointer is pointing at the middle of the list.

4