From 5f2b55ffee9b8c1e75dbf4ebd3937a47e45db3d2 Mon Sep 17 00:00:00 2001 From: Tyni Egoda Gedarage <83944194+TyniEgodagedarage@users.noreply.github.com> Date: Wed, 19 Oct 2022 19:49:20 +0530 Subject: [PATCH] Create BubleSort --- BubleSort | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 BubleSort diff --git a/BubleSort b/BubleSort new file mode 100644 index 0000000..169ddb5 --- /dev/null +++ b/BubleSort @@ -0,0 +1,29 @@ +# Python program for implementation of Bubble Sort + +def bubbleSort(arr): + n = len(arr) + + swapped = False + + for i in range(n-1): + + for j in range(0, n-i-1): + + + if arr[j] > arr[j + 1]: + swapped = True + arr[j], arr[j + 1] = arr[j + 1], arr[j] + + if not swapped: + + return + + + +arr = [64, 34, 25, 12, 22, 11, 90] + +bubbleSort(arr) + +print("Sorted array is:") +for i in range(len(arr)): + print("% d" % arr[i], end=" ")