Permalink
Browse files

Add notes about bubble sort

  • Loading branch information...
hparra committed Feb 13, 2017
1 parent fa859c0 commit 8212f456d42a0372cedb70425e41de0a79eda89a
Showing with 27 additions and 0 deletions.
  1. +27 −0 bubble-sort.md
View
@@ -0,0 +1,27 @@
Bubble Sort
===========
## tl;dr
Bubble Sort:
- while array is not sorted:
- assume it is sorted
- iterate through array
- if pair of elements out of order
- swap them
- mark array as unsorted
## Implementation
```python
def bubblesort(a):
"""Sort an array, `a` in ascending order"""
is_sorted = False
while not is_sorted:
is_sorted = True
for i in xrange(len(a) - 1):
if a[i] > a[i+1]:
a[i], a[i+1] = a[i+1], a[i]
is_sorted = False
return is_sorted
```

0 comments on commit 8212f45

Please sign in to comment.