From 438cebaa582a623e8fc192cf97a3d2f856b4f1b4 Mon Sep 17 00:00:00 2001 From: Jaideep Singh <79747022+Jaideep25-tech@users.noreply.github.com> Date: Wed, 5 Oct 2022 00:35:00 +0530 Subject: [PATCH] Create BubbleSort.py --- .../02. Sorting/01. Bubble Sort/BubbleSort.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 02. Algorithms/02. Sorting/01. Bubble Sort/BubbleSort.py diff --git a/02. Algorithms/02. Sorting/01. Bubble Sort/BubbleSort.py b/02. Algorithms/02. Sorting/01. Bubble Sort/BubbleSort.py new file mode 100644 index 0000000..447bc26 --- /dev/null +++ b/02. Algorithms/02. Sorting/01. Bubble Sort/BubbleSort.py @@ -0,0 +1,15 @@ +# Creating a bubble sort function +def bubble_sort(list1): + # Outer loop for traverse the entire list + for i in range(0,len(list1)-1): + for j in range(len(list1)-1): + if(list1[j]>list1[j+1]): + temp = list1[j] + list1[j] = list1[j+1] + list1[j+1] = temp + return list1 + +list1 = [5, 3, 8, 6, 7, 2] +print("The unsorted list is: ", list1) +# Calling the bubble sort function +print("The sorted list is: ", bubble_sort(list1))