mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-17 06:11:43 +01:00
Rename files to Ruby's common usage
This commit is contained in:
parent
a55f9d026a
commit
5a6e6fcf4c
5 changed files with 27 additions and 0 deletions
27
shell_sort.rb
Normal file
27
shell_sort.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
def shell_sort(a)
|
||||
n=a.length
|
||||
h=1
|
||||
|
||||
while (h<n/3) #for computing increment factor "h"
|
||||
h= (3*h)+1
|
||||
end
|
||||
|
||||
while h>=1
|
||||
# Logic of insertion sort with inrement steps of "h"
|
||||
for i in h...n
|
||||
j=i
|
||||
while j>=h
|
||||
if a[j-h]>a[j]
|
||||
temp=a[j]
|
||||
a[j]=a[j-h]
|
||||
a[j-h]=temp
|
||||
end
|
||||
j-=h
|
||||
end
|
||||
end
|
||||
h/=3
|
||||
end
|
||||
|
||||
return a
|
||||
|
||||
end
|
Loading…
Reference in a new issue