From 9b5c1a311a1d44efd4df20640d864232e3465a45 Mon Sep 17 00:00:00 2001 From: Sourabh Patil <120791252+Acepatil@users.noreply.github.com> Date: Sun, 1 Oct 2023 18:52:32 +0530 Subject: [PATCH 1/6] Added bubble_sort.py --- bubble_sort/bubble_sort.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 bubble_sort/bubble_sort.py diff --git a/bubble_sort/bubble_sort.py b/bubble_sort/bubble_sort.py new file mode 100644 index 00000000..f0abd5d1 --- /dev/null +++ b/bubble_sort/bubble_sort.py @@ -0,0 +1,22 @@ +def bubble_sort(arr): + """ + Performs a bubble sort + :type arr: int + """ + for index_1 in range(len(arr)): + for index_2 in range(0,len(arr)-index_1-1): + if(arr[index_2]>arr[index_2+1]): + temp=arr[index_2+1] + arr[index_2+1]=arr[index_2] + arr[index_2]=temp + + +def main(): + arr = [2, 3, 0, 4,-4,56,12] + print("Before Sorting") + bubble_sort(arr) + print(arr) + + +if __name__ == '__main__': + main() From 6ec33540b7663f1594969f26179ef0e944db38c6 Mon Sep 17 00:00:00 2001 From: Sourabh Patil <120791252+Acepatil@users.noreply.github.com> Date: Wed, 4 Oct 2023 08:12:15 +0530 Subject: [PATCH 2/6] Fixed line space on line20 bubble_sort.py --- bubble_sort/bubble_sort.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bubble_sort/bubble_sort.py b/bubble_sort/bubble_sort.py index f0abd5d1..764cb144 100644 --- a/bubble_sort/bubble_sort.py +++ b/bubble_sort/bubble_sort.py @@ -1,7 +1,7 @@ def bubble_sort(arr): """ Performs a bubble sort - :type arr: int + : type arr: int """ for index_1 in range(len(arr)): for index_2 in range(0,len(arr)-index_1-1): @@ -16,7 +16,6 @@ def main(): print("Before Sorting") bubble_sort(arr) print(arr) - if __name__ == '__main__': main() From 1976a8a41f2fbdf1b71a93a469b35a776ab7e474 Mon Sep 17 00:00:00 2001 From: Sourabh Patil <120791252+Acepatil@users.noreply.github.com> Date: Wed, 4 Oct 2023 08:15:07 +0530 Subject: [PATCH 3/6] Added space after if statement on line 8 bubble_sort.py --- bubble_sort/bubble_sort.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bubble_sort/bubble_sort.py b/bubble_sort/bubble_sort.py index 764cb144..acd91ea5 100644 --- a/bubble_sort/bubble_sort.py +++ b/bubble_sort/bubble_sort.py @@ -5,7 +5,7 @@ def bubble_sort(arr): """ for index_1 in range(len(arr)): for index_2 in range(0,len(arr)-index_1-1): - if(arr[index_2]>arr[index_2+1]): + if (arr[index_2]>arr[index_2+1]): temp=arr[index_2+1] arr[index_2+1]=arr[index_2] arr[index_2]=temp From babd8a31f98046b037f4d51fbc0939f0983d9681 Mon Sep 17 00:00:00 2001 From: Sourabh Patil <120791252+Acepatil@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:08:30 +0530 Subject: [PATCH 4/6] Update bubble_sort.py --- bubble_sort/bubble_sort.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bubble_sort/bubble_sort.py b/bubble_sort/bubble_sort.py index acd91ea5..687b4be3 100644 --- a/bubble_sort/bubble_sort.py +++ b/bubble_sort/bubble_sort.py @@ -15,7 +15,8 @@ def main(): arr = [2, 3, 0, 4,-4,56,12] print("Before Sorting") bubble_sort(arr) - print(arr) - + print(arr) + + if __name__ == '__main__': main() From 1445447713860b58ea0b998db73bc82d16cb8c89 Mon Sep 17 00:00:00 2001 From: Sourabh Patil <120791252+Acepatil@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:40:18 +0530 Subject: [PATCH 5/6] Update bubble_sort.py --- bubble_sort/bubble_sort.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/bubble_sort/bubble_sort.py b/bubble_sort/bubble_sort.py index 687b4be3..4a9c3ed9 100644 --- a/bubble_sort/bubble_sort.py +++ b/bubble_sort/bubble_sort.py @@ -15,8 +15,7 @@ def main(): arr = [2, 3, 0, 4,-4,56,12] print("Before Sorting") bubble_sort(arr) - print(arr) - + print(arr) if __name__ == '__main__': main() From 8c76e6a57e92def1bd73543aa9a4585b147dfd31 Mon Sep 17 00:00:00 2001 From: Sourabh Patil <120791252+Acepatil@users.noreply.github.com> Date: Tue, 10 Oct 2023 13:47:02 +0530 Subject: [PATCH 6/6] Solved Trailing Space bubble_sort.py --- bubble_sort/bubble_sort.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bubble_sort/bubble_sort.py b/bubble_sort/bubble_sort.py index 4a9c3ed9..bb504fc9 100644 --- a/bubble_sort/bubble_sort.py +++ b/bubble_sort/bubble_sort.py @@ -15,7 +15,8 @@ def main(): arr = [2, 3, 0, 4,-4,56,12] print("Before Sorting") bubble_sort(arr) - print(arr) + print(arr) + if __name__ == '__main__': main()