qsort
using System; def qsort(a : list[IComparable]){ | [] => [] | _ => def g = n => a.Filter(x => x.CompareTo(a.Head) == n); qsort(g(-1)) + g(0) + qsort(g(1)) } def r = Random(DateTime.Now.Millisecond); Console.Write(qsort($[r.Next()|_ in [0..9]]))
def qsort(a){ if(!a) return [] def g = a.groupBy{ it <=> a[0] } qsort(g[-1]) + g[0] + qsort(g[1]) } print qsort((0..9).collect{ Math.random() })
def qsort a return [] if a.nil? or a.empty? g = a.group_by{|x| x <=> a[0] } qsort(g[-1]) + g[0] + qsort(g[1]) end p qsort (0..9).map{ rand }
+
list#Partition を発見。こっちのがいいな。
using System; def qsort(a : list[IComparable]){ | h :: t => def (l, r) = t.Partition(x => x.CompareTo(h) < 0); qsort(l) + [h] + qsort(r) | _ => [] }