Created
August 26, 2014 17:08
-
-
Save hachibeeDI/fe242ffd8114af4f22fc to your computer and use it in GitHub Desktop.
bubble
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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