box-o-sand/PracticingAlgorithms/sorting.rb
Dan Buch eacc351b17 Add 'PracticingAlgorithms/' from commit '0b723f2ae0a20ab8c90c33db8c1d9d9acd76a86f'
git-subtree-dir: PracticingAlgorithms
git-subtree-mainline: 0a9428093c
git-subtree-split: 0b723f2ae0
2013-01-09 23:58:26 -05:00

13 lines
196 B
Ruby

def insertion_sort(a)
(0..(a.length - 1)).each do |j|
key = a[j]
i = j - 1
while (i >= 0) && (a[i] > key)
a[i + 1] = a[i]
i = i - 1
end
a[i + 1] = key
end
end