(* A QuickSort function for int lists. Stephen Freund cs334 *) (* Always include these at the top of your SML files so large datatype values and lists will print fully *) Control.Print.printDepth := 100; Control.Print.printLength := 100; (* Partition: int * int list -> int list * int list Partition list around the pivot, and return the lists of smaller and larger elements. *) fun partition (pivot, nil) = (nil, nil) | partition (pivot, x::xs) = let val (smaller, bigger) = partition (pivot, xs) in if x < pivot then (x::smaller, bigger) else (smaller, x::bigger) end; (* qsort: int list -> int list Sort a list of integers using quick sort. *) fun qsort (nil) = nil | qsort (p::rest) = let val (smaller, bigger) = partition(p,rest) in qsort(smaller) @ [p] @ qsort(bigger) end; qsort [6,23,6,3,78,23,12,6,7,34,7,1,23,7,23,6,3,6];