From de70ebe7e974c0b686d46e541626f845438d23aa Mon Sep 17 00:00:00 2001 From: Chaitanya Dubal <102644586+chaitanyadubal@users.noreply.github.com> Date: Mon, 24 Oct 2022 22:07:25 +0530 Subject: [PATCH] Bubble-sort --- Bubblesort.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Bubblesort.py diff --git a/Bubblesort.py b/Bubblesort.py new file mode 100644 index 0000000..32c3267 --- /dev/null +++ b/Bubblesort.py @@ -0,0 +1,16 @@ +def bubbleesort(list): + for i in range(len(list) - 1, 0, -1): + no_swap = True + for j in range(0, i): + if list[j + 1] < list[j]: + list[j], list[j + 1] = list[j + 1], list[j] + no_swap = False + if no_swap: + return + + +list = input('Enter the list of numbers: ').split() +list = [int(x) for x in list] +bubbleesort(list) +print('Sorted list: ', end='') +print(list)