Skip to content

Commit

Permalink
Fixes issue 436 - fixes median algorithm bug
Browse files Browse the repository at this point in the history
  • Loading branch information
j-haj committed Oct 2, 2017
1 parent a02f273 commit b280c26
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions quick_sort/quick_sort.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ def median(a, i, j, k):
:param k: middle element index
:return: return median of values at indices i, j and k.
"""
if a[i] > a[j]:
if a[j] > a[k]:
return j
else:
return k
else:
if a[i] > a[k]:
return i
else:
return k
ai, aj, ak = a[i], a[j], a[k]
med_val = ai + aj + ak - max(ai, aj, ak) - min(ai, aj, ak)
if ai == med_val:
return i
elif aj == med_val:
return j
return k


def partition(array, l, r):
Expand Down

0 comments on commit b280c26

Please sign in to comment.