Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements the CombSort algorithm #54

Merged
merged 15 commits into from
Oct 9, 2022
Prev Previous commit
Next Next commit
expanding the auxiliary method ltminmax since it's too simple now
  • Loading branch information
nlw0 committed Oct 4, 2022
commit c743043b8d1a272a18463ace3ab61405865b8c15
5 changes: 2 additions & 3 deletions src/SortingAlgorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,13 @@ function sort!(v::AbstractVector, lo::Int, hi::Int, ::TimSortAlg, o::Ordering)
return v
end

ltminmax(o::Ordering, a, b) = lt(o, a, b) ? (a, b) : (b, a)

function sort!(v::AbstractVector, lo::Int, hi::Int, ::CombSortAlg, o::Ordering)
interval = (3 * (hi-lo+1)) >> 2

@inbounds while interval > 1
for j in lo:hi-interval
v[j], v[j+interval] = ltminmax(o, v[j], v[j+interval])
a, b = v[j], v[j+interval]
v[j], v[j+interval] = lt(o, a, b) ? (a, b) : (b, a)
end
interval = (3 * interval) >> 2
end
Expand Down