From afc9d880f1f8d125e5ce0e43f5d078503295211e Mon Sep 17 00:00:00 2001 From: gel Date: Mon, 30 Oct 2017 09:51:05 +0100 Subject: [PATCH] Added bubblesort --- bubblesort.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 bubblesort.py diff --git a/bubblesort.py b/bubblesort.py new file mode 100644 index 0000000..c78b3fe --- /dev/null +++ b/bubblesort.py @@ -0,0 +1,11 @@ +def bubbleSort(alist): + for passnum in range(len(alist)-1,0,-1): + for i in range(passnum): + if alist[i]>alist[i+1]: + temp = alist[i] + alist[i] = alist[i+1] + alist[i+1] = temp + +alist = [54,26,93,17,77,31,44,55,20] +bubbleSort(alist) +print(alist)