From 1a760e943053d19d4f3073e3f2c01f35b5f4d868 Mon Sep 17 00:00:00 2001 From: Muhammad Asad Ur Rehman <110890421+MAsad92@users.noreply.github.com> Date: Tue, 8 Oct 2024 22:33:08 +0500 Subject: [PATCH] Create Bubble Sort Algorithm in Python --- data_structures/Sorting/Bubble-Sort.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 data_structures/Sorting/Bubble-Sort.py diff --git a/data_structures/Sorting/Bubble-Sort.py b/data_structures/Sorting/Bubble-Sort.py new file mode 100644 index 000000000000..430ecd0681bc --- /dev/null +++ b/data_structures/Sorting/Bubble-Sort.py @@ -0,0 +1,12 @@ +a = [10,7,100,60,3,89] +def bSort(a): + n = len(a) + for i in range(n-1): + for j in range(n-i-1): + if a[j] > a[j+1]: + # Swaping elements + a[j], a[j+1] = a[j+1], a[j] + +bSort(a) +print("Sorted array is:") +print(a)