From 467134dee2713f6fad30a71b611c71cac017985e Mon Sep 17 00:00:00 2001 From: Skullheadx <704277@pdsb.net> Date: Tue, 24 Jan 2023 18:32:02 -0500 Subject: [PATCH] Add Bubble Sort --- sorting_algorithms/bubble_sort.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sorting_algorithms/bubble_sort.py b/sorting_algorithms/bubble_sort.py index e69de29..669ceba 100644 --- a/sorting_algorithms/bubble_sort.py +++ b/sorting_algorithms/bubble_sort.py @@ -0,0 +1,11 @@ +# Bubble Sort (O(n^2)) +from utils import swap + + +def bubble_sort(array): + for index1 in range(len(array)): # loop through each element + for index2 in range(index1, len(array)): # loop through each of the next elements + if array[index2] < array[index1]: # if lesser, then swap + swap(array, index1, index2) + return array # return sorted array + -- 2.54.0