QuickSort Function using Prolog Source Code
Quick Sort code:
gtq(X,Y) :- X @> Y.
quicksort( [],[] ).
quicksort( [X | Tail], Sorted) :-
split( X, Tail, Small, Big),
quicksort( Small, SortedSmall),
quicksort( Big, SortedBig),
conc( SortedSmall, [X | SortedBig], Sorted).
split( _, [], [], []).
split( X,[Y | Tail], [Y | Small], Big) :- gtq( X, Y),!, split( X, Tail, Small, Big).
split( X, [Y | Tail], Small, [Y | Big] ) :- split( X, Tail, Small, Big).
conc([],L,L).
conc( [X | L1], L2, [X | L3]) :- conc( L1, L2, L3).
Related Articles
- Appends Two Lists using Prolog Source Code
- Delete all occurrences of an Element from a List using Prolog Source Code
- Delete the Nth Element from the List using Prolog Source Code
- List Length Function using Prolog Source Code
- List Member Function using Prolog Source Code
- List Merge Function using Prolog Source Code
- MergeSort Function using Prolog Source Code
- Powersort Function using Prolog Source Code
