Function implemented to identify the cycles in a linked list
(head)
| 37 | fptr.write(sep) |
| 38 | |
| 39 | def has_cycle(head): |
| 40 | """ |
| 41 | Function implemented to identify the cycles in a linked list |
| 42 | """ |
| 43 | slow = head |
| 44 | fast = head |
| 45 | while fast and fast.next: |
| 46 | slow = slow.next |
| 47 | fast = fast.next.next |
| 48 | if slow == fast: # Checks if the slow and fast pointers have been match into a cycle |
| 49 | return 1 |
| 50 | return 0 |
| 51 | |
| 52 | |
| 53 | if __name__ == '__main__': |