From 7aaba7f0b55d925671c2ded45dd94699f548e644 Mon Sep 17 00:00:00 2001 From: Prathima Kadari Date: Mon, 17 May 2021 22:06:12 +0530 Subject: [PATCH] Added bubble sort program --- bubblesort.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 bubblesort.py diff --git a/bubblesort.py b/bubblesort.py new file mode 100644 index 0000000..68e0251 --- /dev/null +++ b/bubblesort.py @@ -0,0 +1,29 @@ +# bubble sort +# list = 71,5,34,56,3,19 + +def bubbleSort(list): + for passnum in range(len(list)-1,0,-1): + for i in range(passnum): + if list[i]>list[i+1]: + temp=list[i] + list[i]=list[i+1] + list[i+1]=temp + + +alist= list() +number=raw_input("enter the elements") + +for i in range(int(number)): + n=raw_input("number: ") + alist.append(int(n)) + +print "the unsorted array" + +print alist + +bubbleSort(alist); + +print "sorted array" + +print alist +