procedure slowsort(A[], start_idx, end_idx) // Sort array range A[start ... end] in-place.
if start_idx ≥ end_idx then
return
middle_idx := floor( (start_idx + end_idx)/2 )
slowsort(A, start_idx, middle_idx) // (1.1)
slowsort(A, middle_idx + 1, end_idx) // (1.2)
if A[end_idx] < A[middle_idx] then
swap (A, end_idx, middle_idx) // (1.3)
slowsort(A, start_idx, end_idx - 1) // (2)
slowsort :: (Ord a) => [a] -> [a]
slowsort xs
| length xs <= 1 = xs
| otherwise = slowsort xs' ++ [max llast rlast] -- (2)
where m = length xs `div` 2
l = slowsort $ take m xs -- (1.1)
r = slowsort $ drop m xs -- (1.2)
llast = last l
rlast = last r
xs' = init l ++ min llast rlast : init r