Sorting algorithms/Strand sort: Difference between revisions
Content added Content deleted
(Updated second D entry) |
|||
Line 1,284: | Line 1,284: | ||
a = self.dup |
a = self.dup |
||
result = [] |
result = [] |
||
until a.empty? |
|||
sublist = [a.shift] |
sublist = [a.shift] |
||
a.each_with_index |
a.each_with_index.each_with_object([]) { |(val, idx), remove| |
||
next if val <= sublist.last |
|||
sublist << val |
|||
remove << idx |
|||
}.reverse_each {|idx| a.delete_at(idx)} |
|||
result.each_index do |idx| |
|||
break if sublist.empty? |
|||
⚫ | |||
each {|idx| a.delete_at(idx)} |
|||
idx = 0 |
|||
while idx < result.length and not sublist.empty? |
|||
if sublist[0] < result[idx] |
|||
⚫ | |||
end |
|||
idx += 1 |
|||
end |
end |
||
result += sublist |
result += sublist |
||
end |
end |
||
result |
result |
||
end |
end |
||
def strandsort! |
def strandsort! |
||
replace(strandsort) |
|||
end |
end |
||
end |
end |