qsort.pl

loading
details
attribute value
description
owner Johannes Waldmann
uploaded 2017-08-17 03:45:07.0
disk size 645 Bytes
downloadable true
type
attribute value
name no_type
processor id 1
description this is the default benchmark type for rejected benchmarks and benchmarks that are not associated with a type.
owning community none
loading contents
%query: qs(i,o).
%
% Quick Sort : Every bodies favorite sort algorithm
%


% mode: qs[i,o]
qs([], []).
qs(cons(X, L), S) :-
        split(L, X, L1, L2),
	qs(L1, S1),
	qs(L2, S2),
	append(S1, cons(X, S2), S).

% mode: append[i,i,o]
append([], L, L).
append(cons(X, L1), L2, cons(X, L3)) :- append(L1, L2, L3).

% mode: split[i,i,o,o]
split([], X, [], []).
split(cons(X, L), Y, cons(X, L1), L2) :- less(X, Y), split(L, Y, L1, L2).
split(cons(X, L), Y, L1, cons(X, L2)) :- geq(X, Y),  split(L, Y, L1, L2).

% mode: less[i,i]
less(0, s(X)).
less(s(X), s(Y)) :- less(X, Y).

% mode: geq[i,i]
geq(X, X).
geq(s(X), 0).
geq(s(X), s(Y)) :- geq(X, Y).



popout

content may be truncated. 'popout' for larger text window.

actions get anonymous link download benchmark