Skip to content

@lysu /sort.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
shell sort
def get_increase(len)
h = 1
while h < len / 3
h = h * 3 + 1
end
h
end
def shell_sort(list)
inc = get_increase(list.length)
while inc >= 1
(inc...list.length).each do |i|
j = i
while j >= inc and list[j] < list[j - inc]
temp = list[j]
list[j] = list[j - inc]
list[j - inc] = temp
j = j - inc
end
end
inc = inc / 3
end
list
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.