bool floyedDetectionLoop (node* head) { if (head == NULL) { return false; } node* fast = head; node* slow = head; while (fast != NULL && slow != NULL) { fast = fast -> next; if (fast -> next == NULL) { fast = fast -> next; } slow = slow -> next; if (fast == slow) { return true; } } return false; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter