From 4bfddb71e76d931b716242b136ee143f8e1ce679 Mon Sep 17 00:00:00 2001 From: mo khan Date: Wed, 4 Sep 2013 21:59:29 -0600 Subject: use Array#sample instead of finding a random pivot. --- lib/sorting/quick_sort.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/sorting/quick_sort.rb b/lib/sorting/quick_sort.rb index d24b33c..71e414e 100644 --- a/lib/sorting/quick_sort.rb +++ b/lib/sorting/quick_sort.rb @@ -2,7 +2,8 @@ class QuickSort def sort(items) return items if items.size <= 1 - pivot = items[rand(items.size)] + #pivot = items[rand(items.size)] + pivot = items.sample less, pivots, greater = [], [], [] items.each do |x| if x < pivot -- cgit v1.2.3