Cycle detection for linked list