NVIDIA Interview Question

Detect a cycle in a cyclic linked list.

Interview Answers

Anonymous

Mar 8, 2012

Search for Cycle detection on wikipedia.... (super easy)

Anonymous

Jun 8, 2012

Check_Loop(Node * list) { Node* p1=list; Node* p2=list; if (! list) return 0; while ( (p1 != NULL && p2 != NULL) && p1 != p2) { p2= (p2->next) ? (p2->next)->next; p1=p1->next; } /* check why we exist the iteration */ if (p1 != NULL && p2 != NULL) && p1 == p2) return 1; else return 0; }