From f281f4124941da875a81df70b9b91b6eaf529434 Mon Sep 17 00:00:00 2001 From: Desislava Shunina <115353472+desiish@users.noreply.github.com> Date: Tue, 5 Nov 2024 17:12:04 +0200 Subject: Add tasks solutions --- Practicum/pract05/solutions/Task03.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Practicum/pract05/solutions/Task03.cpp (limited to 'Practicum/pract05/solutions/Task03.cpp') 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; +} -- cgit v1.3.1-23-gd82d