Time for an 2014 update…

This commit is contained in:
Ingy döt Net 2014-01-17 05:32:22 +00:00
parent 372c577f83
commit 09687c4926
2520 changed files with 34227 additions and 7318 deletions

View file

@ -1,18 +1,15 @@
class Array
def selectionsort!
0.upto(length - 2) do |i|
(min_idx = i + 1).upto(length - 1) do |j|
if self[j] < self[min_idx]
min_idx = j
end
end
if self[i] > self[min_idx]
self[i], self[min_idx] = self[min_idx], self[i]
for i in 0..length-2
min_idx = i
for j in (i+1)...length
min_idx = j if self[j] < self[min_idx]
end
self[i], self[min_idx] = self[min_idx], self[i]
end
self
end
end
ary = [7,6,5,9,8,4,3,1,2,0]
ary.selectionsort!
p ary.selectionsort!
# => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]