Skip to content

Instantly share code, notes, and snippets.

@hachibeeDI
Created August 26, 2014 17:08
Show Gist options
  • Save hachibeeDI/fe242ffd8114af4f22fc to your computer and use it in GitHub Desktop.
Save hachibeeDI/fe242ffd8114af4f22fc to your computer and use it in GitHub Desktop.
bubble
# -*- coding: utf-8 -*-
from __future__ import (print_function, division, absolute_import, unicode_literals, )
def bubble_sort(xs):
count = len(xs) - 1
def flip(ys):
for i in xrange(count):
first = ys[i]
second = ys[i + 1]
if first > second:
ys[i] = second
ys[i + 1] = first
return ys
for i in xrange(count):
xs = flip(xs)
return xs
if __name__ == "__main__":
li = [1, 3, 6, 2, 0]
v = bubble_sort(li)
assert [0, 1, 2, 3, 6, ] == v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment