Website Summary Files Commits Branches @commit @diff @stats
path: root / Practicum / pract05 / solutions / Task03.cpp
diff options
context:
space:
mode:
1 files changed, 18 insertions, 0 deletions
-rw-r--r--Practicum/pract05/solutions/Task03.cpp18
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;
+}