diff --git a/.DS_Store b/.DS_Store index 1944ae0..dbcb8b0 100644 Binary files a/.DS_Store and b/.DS_Store differ 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)) + diff --git a/sorting/QuickBublesort.py b/sorting/QuickBublesort.py new file mode 100644 index 0000000..62951d3 --- /dev/null +++ b/sorting/QuickBublesort.py @@ -0,0 +1,22 @@ + +# coding: utf-8 + +# In[45]: + + +alist = [54,26,93,17,77,31,44,55,20] +def shortBubbleSort(alist): + exchanges = True + passnum = len(alist)-1 + while passnum > 0 and exchanges: + exchanges = False + for i in range(passnum): + if alist[i]>alist[i+1]: + exchanges = True + temp = alist[i] + alist[i] = alist[i+1] + alist[i+1] = temp + passnum = passnum-1 + return alist +print(shortBubbleSort(alist)) +