Skip to content

Instantly share code, notes, and snippets.

@lysu
Created April 4, 2013 10:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save lysu/5309260 to your computer and use it in GitHub Desktop.
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