Browse Source

Bubble Sort

Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.
pull/5/head
Sunny Pate 6 years ago
parent
commit
72a1d835df
2 changed files with 17 additions and 0 deletions
  1. BIN
      .DS_Store
  2. +17
    -0
      sorting/BubbleSort.py

BIN
.DS_Store View File


+ 17
- 0
sorting/BubbleSort.py View File

@ -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))

Loading…
Cancel
Save