aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/algorithms/impl
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-04-17 23:31:37 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-04-17 23:31:37 +0300
commit779443474b9f8e34e6ad00e5ea1ce1530555ee05 (patch)
tree0fb4bf486e4eb17439e2ea56b4293f24d5dbdd3e /algorithms/impl
parentselection_sort: fix codename (diff)
downloadsorting-algorithms-779443474b9f8e34e6ad00e5ea1ce1530555ee05.tar.gz
sorting-algorithms-779443474b9f8e34e6ad00e5ea1ce1530555ee05.zip
median: quicksort instead of .sort()
Diffstat (limited to '')
-rw-r--r--algorithms/impl/median.py4
1 files changed, 3 insertions, 1 deletions
diff --git a/algorithms/impl/median.py b/algorithms/impl/median.py
index 7bcce76..ba51c71 100644
--- a/algorithms/impl/median.py
+++ b/algorithms/impl/median.py
@@ -2,6 +2,8 @@
# This file is licensed under the terms of the MIT License.
# See LICENSE.txt for details.
+from algorithms.impl.quicksort import quicksort_random
+
from heapq import *
def calc_median_heaps(xs):
@@ -31,7 +33,7 @@ def calc_median_heaps(xs):
def calc_median_sort_first(xs):
if not xs:
return 0.0
- xs.sort()
+ quicksort_random(xs)
if len(xs) % 2:
return xs[len(xs) // 2]
else: