From 07aef1b6836df40cf9caa43c94947cefdc776b73 Mon Sep 17 00:00:00 2001 From: Robert Shepherd <113625774+robertshepherdcpp@users.noreply.github.com> Date: Mon, 2 Feb 2026 19:48:31 +0000 Subject: [PATCH 1/2] Improve bubble sort algorithm logic Refactor bubble sort logic to handle timer stopping and resetting correctly. --- src/Sorters/bubblesorter.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Sorters/bubblesorter.cpp b/src/Sorters/bubblesorter.cpp index 4389f82..a37e30a 100644 --- a/src/Sorters/bubblesorter.cpp +++ b/src/Sorters/bubblesorter.cpp @@ -17,12 +17,18 @@ void BubbleSorter::sortStep() *compared2=i+1; if (values->at(i) > values->at(i + 1)) { std::swap(values->at(i), values->at(i + 1)); + changed = true; } i++; } else{ - i=0; - j++; + if(!changed) { + timer->stop(); + } else { + i=0; + j++; + changed = false; + } } } From 43426d9d6126cb590acaaede63ca04f378a71daa Mon Sep 17 00:00:00 2001 From: Robert Shepherd <113625774+robertshepherdcpp@users.noreply.github.com> Date: Mon, 2 Feb 2026 19:50:34 +0000 Subject: [PATCH 2/2] Add changed flag to BubbleSorter class --- src/Sorters/bubblesorter.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Sorters/bubblesorter.h b/src/Sorters/bubblesorter.h index a6f05b5..d6081a2 100644 --- a/src/Sorters/bubblesorter.h +++ b/src/Sorters/bubblesorter.h @@ -12,6 +12,7 @@ class BubbleSorter : public AbstractSorter private: int i; int j; + bool changed = false; }; #endif // BUBBLESORTER_H