main
 1class QuickSort
 2  def sort(items)
 3    return items if items.size <= 1
 4
 5    #pivot = items[rand(items.size)]
 6    pivot = items.sample
 7    less, pivots, greater = [], [], []
 8    items.each do |x|
 9      comparison = x <=> pivot
10      if comparison == -1
11        less << x
12      elsif comparison == 1
13        greater << x
14      else
15        pivots << x
16      end
17    end
18    sort(less) + pivots + sort(greater)
19  end
20end