From 72a1d835dffaa3d62fbe8ff7c36119cee3b33e53 Mon Sep 17 00:00:00 2001 From: Sunny Pate Date: Sat, 13 Oct 2018 12:46:26 +1100 Subject: [PATCH] Bubble Sort Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order. --- .DS_Store | Bin 6148 -> 6148 bytes sorting/BubbleSort.py | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 sorting/BubbleSort.py diff --git a/.DS_Store b/.DS_Store index 1944ae096e08d1ea5c636e3be00d6df20475c8cb..3e6c0892aebfe69925431265db575a1e33683f03 100644 GIT binary patch delta 21 ccmZoMXffDunU%xHz(hyE*uZ@AZB|Vo07~8lLjV8( delta 21 ccmZoMXffDunU%xD(o{#m*wAA0ZB|Vo084xZQ2+n{ diff --git a/sorting/BubbleSort.py b/sorting/BubbleSort.py new file mode 100644 index 0000000..9c10e42 --- /dev/null +++ b/sorting/BubbleSort.py @@ -0,0 +1,17 @@ + +# coding: utf-8 + +# In[43]: + + +alist = [54,26,93,17,77,31,44,55,20] +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 + return alist +print(bubbleSort(alist)) +