summaryrefslogtreecommitdiff
path: root/lang/prolog/1.8.7/src/quicksort
diff options
context:
space:
mode:
Diffstat (limited to 'lang/prolog/1.8.7/src/quicksort')
-rw-r--r--lang/prolog/1.8.7/src/quicksort14
1 files changed, 14 insertions, 0 deletions
diff --git a/lang/prolog/1.8.7/src/quicksort b/lang/prolog/1.8.7/src/quicksort
new file mode 100644
index 0000000..79276c0
--- /dev/null
+++ b/lang/prolog/1.8.7/src/quicksort
@@ -0,0 +1,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 (_, [], [], []).
+