Commit 1eb4cf6

mo khan <mo@mokhan.ca>
2013-10-13 03:45:25
adjust quick sort to use comparison operator.
1 parent 94c96ee
Changed files (1)
lib
lib/sorting/quick_sort.rb
@@ -6,9 +6,10 @@ class QuickSort
     pivot = items.sample
     less, pivots, greater = [], [], []
     items.each do |x|
-      if x < pivot
+      comparison = x <=> pivot
+      if comparison == -1
         less << x
-      elsif x > pivot
+      elsif comparison == 1
         greater << x
       else
         pivots << x