Skip to content

Instantly share code, notes, and snippets.

View tommottom's full-sized avatar

TOM tommottom

  • http://ai-future.hatenablog.jp/entry/%E3%83%8B%E3%83%BC%E3%83%88%E3%83%97%E3%83%AD%E3%82%B0%E3%83%A9%E3%83%9E%E3%83%BC%E5%B0%B1%E8%81%B7
View GitHub Profile
@ackintosh
ackintosh / gist:5181717
Created March 17, 2013 14:21
Bubble sort in Ruby
class Array
def bubble_sort
tmp = self.dup
res = []
res.push tmp.bubbling until tmp.empty?
res
end
def bubbling
(length - 1).times do |i|
self[i], self[i+1] = self[i+1], self[i] if self[i] < self[i+1]