Skip to content

Instantly share code, notes, and snippets.

@KentaYamada
Created October 14, 2014 05:02
Show Gist options
  • Save KentaYamada/3512ea03f207e710dfb3 to your computer and use it in GitHub Desktop.
Save KentaYamada/3512ea03f207e710dfb3 to your computer and use it in GitHub Desktop.
Bubble SortをPythonのFor文を使ってやってみた
# -*- 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