From 25cd2409488bfdf9d5d167881b1b9dae5ab78915 Mon Sep 17 00:00:00 2001 From: Matthew Grove Date: Wed, 12 Jun 2019 09:49:42 +0100 Subject: [PATCH] Add basic bubble sort code --- bubble-sort.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 bubble-sort.py diff --git a/bubble-sort.py b/bubble-sort.py new file mode 100644 index 0000000..d3e760a --- /dev/null +++ b/bubble-sort.py @@ -0,0 +1,14 @@ +array = [7, 2, 5, 8, 0,1,2,3,4,5,6,7] +swapped = True +print("Original array:", array) + +while swapped: + swapped = False + for i, item in enumerate(array): + if i != len(array) - 1: + if item > array[i + 1]: + array[i] = array[i + 1] + array[i + 1] = item + swapped = True + +print("New array:", array) \ No newline at end of file