mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-14 08:01:05 +01:00
Implement shell sort
This commit is contained in:
parent
5cd15d08d8
commit
b151d68ebb
1 changed files with 19 additions and 0 deletions
19
sorts/ShellSort.rb
Normal file
19
sorts/ShellSort.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
def shell_sort(array)
|
||||
jump = array.length / 2
|
||||
while jump > 0
|
||||
i = 0
|
||||
loop do
|
||||
break if (i+jump) >= array.length
|
||||
array[i], array[i+jump] = array[i+jump], array[i] if array[i] > array[i+jump]
|
||||
i += 1
|
||||
end
|
||||
jump /= 2
|
||||
end
|
||||
|
||||
array
|
||||
end
|
||||
puts "Enter a list of numbers seprated by space"
|
||||
|
||||
list = gets
|
||||
bubble_sort(list)
|
||||
print list
|
Loading…
Reference in a new issue