From ace26c77eff2c765282b5c294fc90f3ea3c3be43 Mon Sep 17 00:00:00 2001 From: Rahul Sharma <40543186+Rahulsharma4298@users.noreply.github.com> Date: Thu, 1 Oct 2020 22:12:32 +0530 Subject: [PATCH] Added Bubble sort program Bubble sort with optimization --- sorting and basics/bubble_sort.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 sorting and basics/bubble_sort.py diff --git a/sorting and basics/bubble_sort.py b/sorting and basics/bubble_sort.py new file mode 100644 index 0000000..a9a283d --- /dev/null +++ b/sorting and basics/bubble_sort.py @@ -0,0 +1,10 @@ +def bubble_sort(list): + for i in range(len(list)): + for j in range(len(list)-1-i): + if list[j]>list[j+1]: + list[j], list[j+1] = list[j+1], list[j] + return list + + +list = [9,5,3,7,1,18,12] +print(bubble_sort(list))