1 2 3 4 5 6 7 8 9 10 11 12 13 14
(* quicksort algorithm nach Clocksin-Mellish *) (* Example : quicksort ([1,3,2,4], [1,2,3,4], []) *) quicksort ([H|T], S, X) :- split (H, T, A, B), quicksort (A, S, [H|Y]), quicksort (B, Y, X). quicksort ([], X, X). split (H, [A|X], [A|Y], Z) :- A <= H, split (H, X, Y, Z). split (H, [A|X], Y, [A|Z]) :- split (H, X, Y, Z). split (_, [], [], []).