diff options
1 files changed, 18 insertions, 0 deletions
| -rw-r--r-- | Practicum/pract05/solutions/Task03.cpp | 18 |
diff --git a/Practicum/pract05/solutions/Task03.cpp b/Practicum/pract05/solutions/Task03.cpp new file mode 100644 index 0000000..42282c6 --- /dev/null +++ b/Practicum/pract05/solutions/Task03.cpp @@ -0,0 +1,18 @@ +bool has_cycle(SinglyLinkedListNode* head) { + if(!head) + return false; + + SinglyLinkedListNode* slow = head; + SinglyLinkedListNode* fast = head; + + while(fast && fast->next) + { + slow = slow->next; + fast = fast->next->next; + + if(slow == fast) + return true; + } + + return false; +} |
