Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
merge sort
def merge(list, low, mid, high)
aux = []
low.upto(high) do |copier_index|
aux[copier_index] = list[copier_index]
end
i = low
j = mid + 1
low.upto(high) do | index |
if i > mid
list[index] = aux[j]
j += 1
elsif j > high
list[index] = aux[i]
i += 1
elsif aux[j] < aux[i]
list[index] = aux[j]
j += 1
else
list[index] = aux[i]
i += 1
end
end
list
end
def merge_sort(list, low, high)
if high <= low
return
end
mid = low + (high - low) / 2
merge_sort(list, low, mid)
merge_sort(list, mid + 1, high)
merge(list, low, mid, high)
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.