HGPA

Bubble Sort

tl;dr

Bubble Sort:

Implementation

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
Filename: bubble-sort.md (Edit)
Modified: 2017-02-13 (8212f456d42a0372cedb70425e41de0a79eda89a)
Created: 2017-02-13 (8212f456d42a0372cedb70425e41de0a79eda89a)