Skip to content

Instantly share code, notes, and snippets.

@sunny0425
Created November 1, 2016 02:09
Show Gist options
  • Save sunny0425/bdbab353a32fcbcfdfae8ceb18d5627f to your computer and use it in GitHub Desktop.
Save sunny0425/bdbab353a32fcbcfdfae8ceb18d5627f to your computer and use it in GitHub Desktop.
冒泡排序
def bubble_sort(arr)
len = arr.length
(0..len).each do |i|
j = 0
while j < len - i - 1
if arr[j] > arr[j+1].to_i
x = arr[j]
arr[j] = arr[j+1]
arr[j+1] = x
end
j = j + 1
end
end
return arr
end
bubble_sort([25,56,49,78,11,65,41,36])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment