Skip to content

Instantly share code, notes, and snippets.

@yesidays
Created January 15, 2012 04:53
Show Gist options
  • Save yesidays/1614393 to your computer and use it in GitHub Desktop.
Save yesidays/1614393 to your computer and use it in GitHub Desktop.
code.jobs - Quicksort - Prolog
% Quicksort.
% quicksort( List, SortedList): sort List by the quicksort algorithm
quicksort( [], []).
quicksort( [X|Tail], Sorted) :-
split( X, Tail, Small, Big),
quicksort( Small, SortedSmall),
quicksort( Big, SortedBig),
conc( SortedSmall, [X|SortedBig], Sorted).
split( X, [], [], []).
split( X, [Y|Tail], [Y|Small], Big) :-
gt( X, Y), !,
split( X, Tail, Small, Big).
split( X, [Y|Tail], Small, [Y|Big]) :-
split( X, Tail, Small, Big).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment