From 779443474b9f8e34e6ad00e5ea1ce1530555ee05 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 17 Apr 2016 23:31:37 +0300 Subject: median: quicksort instead of .sort() --- algorithms/impl/median.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'algorithms/impl') 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: -- cgit v1.2.3