Created
October 14, 2014 05:02
-
-
Save KentaYamada/3512ea03f207e710dfb3 to your computer and use it in GitHub Desktop.
Bubble SortをPythonのFor文を使ってやってみた
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 -*- | |
def bubble_sort(arr): | |
for i in arr: | |
for j in range(len(arr) - 1): | |
if arr[j] > arr [j + 1]: | |
tmp = arr[j] | |
arr[j] = arr[j + 1] | |
arr[j + 1] = tmp | |
return arr | |
if __name__ == '__main__': | |
arr = [2, 5, 1, 3, 9] | |
print (arr) | |
arr = bubble_sort(arr) | |
print (arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment