summaryrefslogtreecommitdiff
path: root/lang/prolog/1.8.7/src/quicksort
blob: 79276c0f85e637391550b0cdf5149f1b336df16d (plain)
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 (_, [], [], []).