Website Summary Files Commits Branches @commit @diff @stats
path: root / Practicum / pract05 / solutions / Task03.cpp
diff options
context:
space:
mode:
Commitf281f4124941da875a81df70b9b91b6eaf529434 (patch)
Author
 Desislava Shunina <115353472+desiish@users.noreply.github.com>
2024-11-05 17:12:04 +0200
Committer
 GitHub <noreply@github.com>
2024-11-05 17:12:04 +0200
Files7c5582db28bce2ec847e8279855584244a3ac2b3 /Practicum/pract05/solutions/Task03.cpp
Data-structures-and-algorithms-f281f4124941da875a81df70b9b91b6eaf529434.tar
Data-structures-and-algorithms-f281f4124941da875a81df70b9b91b6eaf529434.tar.gz
Data-structures-and-algorithms-f281f4124941da875a81df70b9b91b6eaf529434.zip
Parent8d143a1431e7fbc943524b3897afca0139a5f43b (diff)
Add tasks solutions
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;
+}