- #!/usr/bin/env ruby
- def qSort( ls )
- return ls if ( ls.length < 2 )
- pivIdx = rand ls.length
- pivots = ls.select { |e| e == ls[pivIdx] }
- low = ls.select { |e| e < ls[pivIdx] }
- high = ls.select { |e| e > ls[pivIdx] }
- return qSort( low ) + pivots + qSort( high )
- end
- puts "ls #{qSort( [ 1, 32, 14, 12, 19, 94, 38, 28, 40, 38, 42, 18, 23, 13, 37] ).join(", ")}"