Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash authored and waTeim committed Nov 23, 2014
1 parent b6a6457 commit d78581c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions base/sort.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,16 @@ function sort!(v::AbstractVector, lo::Int, hi::Int, a::QuickSortAlg, o::Ordering
v[i], v[j] = v[j], v[i]
end
v[j], v[lo] = v[lo], v[j]
lo < (j-1) && sort!(v, lo, j-1, a, o)
lo = j+1
if j-lo < hi-j
# recurse on the smaller chunk
# this is necessary to preserve O(log(n))
# stack space in the worst case (rather than O(n))
lo < (j-1) && sort!(v, lo, j-1, a, o)
lo = j+1
else
j+1 < hi && sort!(v, j+1, hi, a, o)
hi = j-1
end
end
return v
end
Expand Down

0 comments on commit d78581c

Please sign in to comment.