From c36fbcfd74ae1960eeeddba498bcca13374f32a8 Mon Sep 17 00:00:00 2001 From: Pavel Kuliaka Date: Sat, 4 Oct 2025 20:59:23 +0300 Subject: [PATCH] Implemented a bubble sorting algorithm --- src/Homework #3/SortingAlgorithm/algorithm.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/Homework #3/SortingAlgorithm/algorithm.py diff --git a/src/Homework #3/SortingAlgorithm/algorithm.py b/src/Homework #3/SortingAlgorithm/algorithm.py new file mode 100644 index 0000000..3df8a9e --- /dev/null +++ b/src/Homework #3/SortingAlgorithm/algorithm.py @@ -0,0 +1,12 @@ +def bubble_sort(array: list) -> list: + array_legth = len(array) + for _ in range(0, array_legth-1): + for index in range(0, array_legth-1): + if array[index] > array[index+1]: + array[index], array[index+1] = array[index+1], array[index] + return array + + +test_array = [4, 2, 5, 4, 7, 1, 3] +print(bubble_sort(test_array)) +